2024-10-04 17:50:03 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
RedisURL string `json:"redisURL"`
|
2024-10-23 19:43:52 -04:00
|
|
|
MongoDBURL string `json:"mongoDBURL"`
|
2024-10-04 17:50:03 -04:00
|
|
|
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
|
|
|
|
}
|