main file for config package

master
Matthew 2024-10-04 17:50:03 -04:00
parent 0fef07cfae
commit 29588e0829
Signed by: matthew
SSH Key Fingerprint: SHA256:piIXekA9q1p0ZGi4ogFbNY1embip5Ytbi3v8AZ8UYq4
1 changed files with 36 additions and 0 deletions

36
config/main.go Normal file
View File

@ -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
}