33 lines
503 B
Go
33 lines
503 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
toml "github.com/BurntSushi/toml"
|
||
|
"github.com/charmbracelet/log"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
Hostname string
|
||
|
Port int
|
||
|
}
|
||
|
|
||
|
func LoadConfig() Config {
|
||
|
|
||
|
log.Info("Loading the config file")
|
||
|
|
||
|
dat, err := os.ReadFile("./config.toml")
|
||
|
if err != nil {
|
||
|
log.Error("Failed to load config file", "err", err)
|
||
|
// Use default values
|
||
|
return Config{
|
||
|
Hostname: "localhost",
|
||
|
Port: 8000,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var conf Config
|
||
|
_, err = toml.Decode(string(dat), &conf)
|
||
|
return conf
|
||
|
}
|