wip
This commit is contained in:
@@ -1,20 +1,38 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type DatabaseConfig struct {
|
||||
DBPath string `json:"DBPath"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DB DatabaseConfig `json:"db"`
|
||||
}
|
||||
|
||||
func LoadConfig() *Config {
|
||||
return &Config{
|
||||
DBUser: os.Getenv("DB_USER"),
|
||||
DBPassword: os.Getenv("DB_PASSWORD"),
|
||||
DBName: os.Getenv("DB_NAME"),
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user