Added configurable storage file + some cosmetic changes
Signed-off-by: Artur Marud <artur@status.im>
This commit is contained in:
parent
33983caa92
commit
68db7fadb9
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
2
main.go
2
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 {
|
||||
|
|
|
@ -19,6 +19,11 @@ type mapRepository struct {
|
|||
}
|
||||
|
||||
func NewMapRepository(filename string) Repository {
|
||||
|
||||
if filename == "" {
|
||||
filename = "stateStore.json"
|
||||
}
|
||||
|
||||
repo := new(mapRepository)
|
||||
repo.filename = filename
|
||||
|
||||
|
|
Loading…
Reference in New Issue