budget-go/config/config.go
2024-09-14 23:37:03 +02:00

55 lines
870 B
Go

package config
import (
"log"
"gopkg.in/ini.v1"
)
type database struct {
Dsn string
}
type logging struct {
Level string
}
type security struct {
Secret string
}
type server struct {
Address string
Port int
}
type Config struct {
Database database
Log logging
Security security
Server server
}
var config *Config
func Get() *Config {
if config == nil {
config = &Config{}
}
return config
}
func (c *Config) Load(file string) {
cfg, err := ini.Load(file)
if err != nil {
log.Fatal(err)
}
config.Database.Dsn = cfg.Section("database").Key("dsn").String()
config.Log.Level = cfg.Section("log").Key("level").String()
config.Security.Secret = cfg.Section("security").Key("secret").String()
config.Server.Address = cfg.Section("server").Key("address").String()
config.Server.Port, _ = cfg.Section("server").Key("port").Int()
}