diff --git a/config/entity.go b/config/entity.go index 6b78284..4f42c7f 100644 --- a/config/entity.go +++ b/config/entity.go @@ -4,6 +4,7 @@ type Config struct { //ConsulToken string `json:"consulKey"` CloudflareToken string `json:"cloudflareKey"` DomainName string `json:"domain"` - HostTimeout int `json:"hostLivenessTimeout"` + HostTimeout int `json:"hostTimeout"` LogLevel string `json:"logLevel"` + StorageFilePath string `json:"storageFilePath"` } diff --git a/config/service.go b/config/service.go index 122cf06..c865c4f 100644 --- a/config/service.go +++ b/config/service.go @@ -28,13 +28,13 @@ func (s *service) LoadConfig(fileName string) (*Config, error) { 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 { - 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) 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 &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 } diff --git a/main.go b/main.go index 01e486c..57b2192 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,7 @@ func main() { hosts := consul.GetHostnames() //Open statestore - statestore := statestore.NewService(statestore.NewMapRepository("statestore.json")) + statestore := statestore.NewService(statestore.NewMapRepository(config.StorageFilePath)) //Iterate over hosts and check modify indexes for _, hostname := range hosts { diff --git a/statestore/mapRepository.go b/statestore/mapRepository.go index 5f9ff7e..57fa802 100644 --- a/statestore/mapRepository.go +++ b/statestore/mapRepository.go @@ -19,6 +19,11 @@ type mapRepository struct { } func NewMapRepository(filename string) Repository { + + if filename == "" { + filename = "stateStore.json" + } + repo := new(mapRepository) repo.filename = filename