Added configurable storage file + some cosmetic changes

Signed-off-by: Artur Marud <artur@status.im>
This commit is contained in:
Artur Marud 2022-07-27 13:36:51 +02:00
parent 33983caa92
commit 68db7fadb9
No known key found for this signature in database
GPG Key ID: 3A50153F6C80C7F9
4 changed files with 17 additions and 6 deletions

View File

@ -4,6 +4,7 @@ type Config struct {
//ConsulToken string `json:"consulKey"` //ConsulToken string `json:"consulKey"`
CloudflareToken string `json:"cloudflareKey"` CloudflareToken string `json:"cloudflareKey"`
DomainName string `json:"domain"` DomainName string `json:"domain"`
HostTimeout int `json:"hostLivenessTimeout"` HostTimeout int `json:"hostTimeout"`
LogLevel string `json:"logLevel"` LogLevel string `json:"logLevel"`
StorageFilePath string `json:"storageFilePath"`
} }

View File

@ -28,13 +28,13 @@ func (s *service) LoadConfig(fileName string) (*Config, error) {
return nil, errors.New("cannot find env variable DOMAIN_NAME") return nil, errors.New("cannot find env variable DOMAIN_NAME")
} }
hostTimeout, exists := os.LookupEnv("HOST_LIVENESS_TIMEOUT") hostTimeout, exists := os.LookupEnv("HOST_TIMEOUT")
if !exists { if !exists {
return nil, errors.New("cannot find env variable HOST_LIVENESS_TIMEOUT") return nil, errors.New("cannot find env variable HOST_TIMEOUT")
} }
hostTimeoutInt, err := strconv.ParseInt(hostTimeout, 10, 32) hostTimeoutInt, err := strconv.ParseInt(hostTimeout, 10, 32)
if err != nil { if err != nil {
return nil, errors.New("incorrect HOST_LIVENESS_TIMEOUT value") return nil, errors.New("incorrect HOST_TIMEOUT value")
} }
@ -43,7 +43,12 @@ func (s *service) LoadConfig(fileName string) (*Config, error) {
return nil, errors.New("cannot find env variable LOG_LEVEL") return nil, errors.New("cannot find env variable LOG_LEVEL")
} }
return &Config{CloudflareToken: cfToken, DomainName: domainaName, HostTimeout: int(hostTimeoutInt), LogLevel: logLevel}, nil storageFilePath, exists := os.LookupEnv(("STORAGE_FILEPATH"))
if !exists {
return nil, errors.New("cannot find env variable STORAGE_FILEPATH")
}
return &Config{CloudflareToken: cfToken, DomainName: domainaName, HostTimeout: int(hostTimeoutInt), LogLevel: logLevel, StorageFilePath: storageFilePath}, nil
} }

View File

@ -44,7 +44,7 @@ func main() {
hosts := consul.GetHostnames() hosts := consul.GetHostnames()
//Open statestore //Open statestore
statestore := statestore.NewService(statestore.NewMapRepository("statestore.json")) statestore := statestore.NewService(statestore.NewMapRepository(config.StorageFilePath))
//Iterate over hosts and check modify indexes //Iterate over hosts and check modify indexes
for _, hostname := range hosts { for _, hostname := range hosts {

View File

@ -19,6 +19,11 @@ type mapRepository struct {
} }
func NewMapRepository(filename string) Repository { func NewMapRepository(filename string) Repository {
if filename == "" {
filename = "stateStore.json"
}
repo := new(mapRepository) repo := new(mapRepository)
repo.filename = filename repo.filename = filename