Files
GoMembership/internal/config/config.go
$(pass /github/name) 9bd8d48243 wip
2024-07-02 00:27:43 +02:00

39 lines
681 B
Go

package config
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
type DatabaseConfig struct {
DBPath string `json:"DBPath"`
}
type Config struct {
DB DatabaseConfig `json:"db"`
}
func LoadConfig() *Config {
path, err := os.Getwd()
if err != nil {
log.Fatalf("could not get working directory: %v", err)
}
configFile, err := os.Open(filepath.Join(path, "configs", "config.json"))
if err != nil {
log.Fatalf("could not open config file: %v", err)
}
defer configFile.Close()
decoder := json.NewDecoder(configFile)
config := &Config{}
err = decoder.Decode(config)
if err != nil {
log.Fatalf("could not decode config file: %v", err)
}
return config
}