fyp/logic/utils/config.go

54 lines
1.1 KiB
Go
Raw Normal View History

package utils
import (
"os"
toml "github.com/BurntSushi/toml"
"github.com/charmbracelet/log"
)
2024-04-12 20:36:23 +01:00
type WorkerConfig struct {
NumberOfWorkers int `toml:"number_of_workers"`
Pulling string `toml:"pulling_time"`
}
type Config struct {
Hostname string
Port int
2024-04-12 20:36:23 +01:00
NumberOfWorkers int `toml:"number_of_workers"`
SupressCuda int `toml:"supress_cuda"`
GpuWorker WorkerConfig `toml:"Worker"`
}
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,
2024-04-12 20:36:23 +01:00
GpuWorker: WorkerConfig{
NumberOfWorkers: 1,
Pulling: "500ms",
},
}
}
var conf Config
_, err = toml.Decode(string(dat), &conf)
2024-04-12 20:36:23 +01:00
if conf.SupressCuda == 1 {
log.Warn("Supressing Cuda Messages!")
os.Setenv("TF_CPP_MIN_VLOG_LEVEL", "3")
os.Setenv("TF_CPP_MIN_LOG_LEVEL", "3")
}
return conf
}