1
0
mirror of https://github.com/nxshock/gallery.git synced 2024-11-27 00:11:00 +05:00
gallery/config.go

37 lines
804 B
Go
Raw Permalink Normal View History

2023-01-08 14:52:16 +05:00
package main
import (
"path/filepath"
"github.com/ilyakaznacheev/cleanenv"
)
type Config struct {
WorkingDirectory string `env-default:"."`
Crf uint64 `env-default:"40"`
ProcessCount uint64 `env-default:"4"`
}
func loadConfig(path string) (*Config, error) {
var config Config
err := cleanenv.ReadConfig("gallery.toml", &config)
if err != nil {
return nil, err
}
2023-04-10 19:56:46 +05:00
config.WorkingDirectory = filepath.ToSlash(config.WorkingDirectory)
if len(config.WorkingDirectory) > 0 && string(config.WorkingDirectory[len(config.WorkingDirectory)-1]) != "/" {
config.WorkingDirectory += "/"
}
2023-01-08 14:52:16 +05:00
workingDirectory, err := filepath.Abs(config.WorkingDirectory)
if err != nil {
return nil, err
}
2023-04-10 19:56:46 +05:00
config.WorkingDirectory = filepath.ToSlash(workingDirectory)
2023-01-08 14:52:16 +05:00
return &config, nil
}