ref: f79a9d09c451653ff27fb34afb5b0c71dc758a32
server/config/config.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
package config import ( "fmt" "github.com/tkanos/gonfig" ) type ArchiveFrequency int const ( Daily ArchiveFrequency = iota Weekly Monthly ) var archFrequency = map[string]ArchiveFrequency{ "daily": Daily, "weekly": Weekly, "monthly": Monthly, } func main() { interval := archFrequency["daily"] fmt.Println(interval) //print the enum value } type Configuration struct { DB_USERNAME string `json:"databaseUsername"` DB_PASSWORD string `json:"databasePassword"` DB_PORT string `json:"databasePort"` DB_HOST string `json:"databaseHost"` DB_NAME string `json:"databaseSchema"` REST_ADDRESS string `json:"restAddress"` ARCHIVE_FREQUENCY string `json:"archiveFrequency"` ARCHIVE_DIRECTORY string `json:"archiveDirectory"` } func GetConfig(fileName string) Configuration { configuration := Configuration{} gonfig.GetConf(fileName, &configuration) return configuration } |