0.2.1 databatage conectage

This commit is contained in:
Peder Vatn Austad
2024-05-24 22:50:31 +02:00
parent 8eeb4a0612
commit be137e0883
7 changed files with 112 additions and 1 deletions

35
config/config.go Normal file
View File

@@ -0,0 +1,35 @@
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
}