package main import ( "encoding/json" "os" ) type HTTPServer struct { Port string `json:"port"` Addr string `json:"addr"` } type Redis struct { Addr string `json:"addr"` DB int `json:"db"` } type GqlConfig struct { ClientID string `json:"clientId"` } type Config struct { HTTPServer HTTPServer `json:"http_server"` Redis Redis `json:"redis"` Gql GqlConfig `json:"gql"` DbPath string `json:"dbpath"` } func loadConfig(configPath string) Config { // Default config in case a value is missing in the config file var config = Config{ HTTPServer: HTTPServer{ Addr: "127.0.0.1", Port: "8080", }, Redis: Redis{ Addr: "127.0.0.1:6379", DB: 0, }, Gql: GqlConfig{ ClientID: "ue6666qo983tsx6so1t0vnawi233wa", }, DbPath: "./database.sqlite3", } file, err := os.ReadFile(configPath) if err != nil { logger.Error().Msg("Failed to read config file. The default config will be used") return config } err = json.Unmarshal(file, &config) if err != nil { logger.Error().Msg("Failed to parse config file. The default config will be used") return config } return config }