cr-report-app/config/main.go

38 lines
705 B
Go

package config
import (
"encoding/json"
"os"
)
type Config struct {
RedisURL string `json:"redisURL"`
MongoDBURL string `json:"mongoDBURL"`
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
}