...
1
19
20 package config
21
22 import (
23 "discovery/log"
24 "encoding/json"
25 "io/ioutil"
26 "os"
27 )
28
29 func GetConfigurationDynamicFilePath() string {
30 return GetDataPath() + "/" + ConfigurationFileName
31 }
32
33 func SaveConfigurationDynamicToConfigFile() error {
34
35 err := CreateDataFolder()
36 if err != nil {
37 log.Log.Errorf("Cannot create folder %s: %s", GetDataPath(), err.Error())
38 return err
39 }
40
41
42 configJson, err := json.MarshalIndent(configurationDynamic, "", " ")
43 err = ioutil.WriteFile(GetConfigurationDynamicFilePath(), configJson, 0644)
44 if err != nil {
45 log.Log.Errorf("Cannot save configuration to file %s: %s", GetConfigurationDynamicFilePath(), err.Error())
46 return err
47 }
48
49 return nil
50 }
51
52 func CreateDataFolder() error {
53
54 if _, err := os.Stat(GetDataPath()); !os.IsNotExist(err) {
55 return nil
56 }
57
58
59 err := os.Mkdir(GetDataPath(), 0664)
60 if err != nil {
61 log.Log.Errorf("Cannot create folder %s: %s", GetDataPath(), err.Error())
62 return err
63 }
64
65 return nil
66 }
67
View as plain text