36 lines
753 B
Go
36 lines
753 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Database struct {
|
|
Host string `json:"host"`
|
|
Port string `json:"port"`
|
|
User string `json:"user"`
|
|
Password string `json:"password"`
|
|
DBName string `json:"dbname"`
|
|
SSLMode string `json:"sslmode"`
|
|
} `json:"database"`
|
|
Temp string `json:"temp"`
|
|
}
|
|
|
|
func LoadConfig(file string) (Config, error) {
|
|
var config Config
|
|
configFile, err := os.Open(file)
|
|
if err != nil {
|
|
return config, fmt.Errorf("failed to open config file: %w", err)
|
|
}
|
|
defer configFile.Close()
|
|
|
|
jsonParser := json.NewDecoder(configFile)
|
|
if err := jsonParser.Decode(&config); err != nil {
|
|
return config, fmt.Errorf("failed to parse config file: %w", err)
|
|
}
|
|
|
|
return config, nil
|
|
}
|