65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package configs
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/google/uuid"
|
|
"trle5.xyz/upscayl-server/utils/yaml"
|
|
)
|
|
|
|
const configPath = "config.yaml"
|
|
|
|
var (
|
|
AccessToken string
|
|
DefaultModel string
|
|
|
|
ModelsDir = "models"
|
|
|
|
InputDir = "input"
|
|
OuputDir = "output"
|
|
)
|
|
|
|
type config struct {
|
|
AccessToken string `yaml:"AccessToken"`
|
|
DefaultModel string `yaml:"DefaultModel"`
|
|
|
|
ModelsDir string `yaml:"ModelsDir"`
|
|
|
|
InputDir string `yaml:"InputDir"`
|
|
OuputDir string `yaml:"OuputDir"`
|
|
}
|
|
|
|
func LoadConfig() {
|
|
_, err := os.Stat(configPath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
err = yaml.SaveYAML(configPath, &config{
|
|
AccessToken: uuid.NewString(),
|
|
|
|
ModelsDir: "models",
|
|
|
|
InputDir: "input",
|
|
OuputDir: "output",
|
|
})
|
|
if err != nil {
|
|
log.Fatalln("failed to create config file:", err)
|
|
}
|
|
} else {
|
|
log.Fatalln("failed to stat config file:", err)
|
|
}
|
|
}
|
|
|
|
var c config
|
|
|
|
err = yaml.LoadYAML(configPath, &c)
|
|
if err != nil {
|
|
log.Fatalln("failed to load config:", err)
|
|
}
|
|
|
|
AccessToken = c.AccessToken
|
|
DefaultModel = c.DefaultModel
|
|
InputDir = c.InputDir
|
|
ModelsDir = c.ModelsDir
|
|
}
|