2024-04-08 15:47:31 +01:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
toml "github.com/BurntSushi/toml"
|
|
|
|
"github.com/charmbracelet/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2024-04-08 17:45:32 +01:00
|
|
|
Hostname string
|
|
|
|
Port int
|
|
|
|
NumberOfWorkers int `toml:"number_of_workers"`
|
2024-04-08 15:47:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2024-04-08 17:45:32 +01:00
|
|
|
Hostname: "localhost",
|
|
|
|
Port: 8000,
|
|
|
|
NumberOfWorkers: 10,
|
2024-04-08 15:47:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var conf Config
|
|
|
|
_, err = toml.Decode(string(dat), &conf)
|
|
|
|
return conf
|
|
|
|
}
|