diff --git a/config/main.go b/config/main.go new file mode 100644 index 0000000..8711cc0 --- /dev/null +++ b/config/main.go @@ -0,0 +1,36 @@ +package config + +import ( + "encoding/json" + "os" +) + +type Config struct { + RedisURL string `json:"redisURL"` + ServiceAddress string `json:"serviceAddress"` + WebServerPort int `json:"webServerPort"` +} + +func LoadConfig(file string) (*Config, error) { + // Open the config file + configFile, err := os.Open(file) + if err != nil { + return nil, err + } + defer func(configFile *os.File) { + err := configFile.Close() + if err != nil { + return + } + }(configFile) + + // Parse the JSON file into a Config struct + var config Config + decoder := json.NewDecoder(configFile) + err = decoder.Decode(&config) + if err != nil { + return nil, err + } + + return &config, nil +}