35 lines
606 B
Go
35 lines
606 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
|
|
toml "github.com/BurntSushi/toml"
|
|
"github.com/charmbracelet/log"
|
|
)
|
|
|
|
type Config struct {
|
|
Hostname string
|
|
Port int
|
|
NumberOfWorkers int `toml:"number_of_workers"`
|
|
}
|
|
|
|
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,
|
|
NumberOfWorkers: 10,
|
|
}
|
|
}
|
|
|
|
var conf Config
|
|
_, err = toml.Decode(string(dat), &conf)
|
|
return conf
|
|
}
|