yans/internal/config/config.go

37 lines
741 B
Go
Raw Permalink Normal View History

2022-01-17 22:38:56 +00:00
package config
import (
"github.com/BurntSushi/toml"
"os"
)
2022-01-19 19:51:08 +00:00
const (
SQLiteBackendType = "sqlite"
)
2022-01-17 22:38:56 +00:00
type Config struct {
2022-01-19 19:51:08 +00:00
Address string `toml:"address"`
Port int `toml:"port"`
2022-04-13 10:10:11 +00:00
WSPort int `toml:"ws_port"`
2022-01-19 19:51:08 +00:00
BackendType string `toml:"backend_type"`
2022-02-03 16:44:08 +00:00
Domain string `toml:"domain"`
2022-01-19 19:51:08 +00:00
SQLite SQLiteBackendConfig `toml:"sqlite"`
2022-04-12 00:29:22 +00:00
UploadPath string `toml:"upload_path"`
2022-01-19 19:51:08 +00:00
}
type SQLiteBackendConfig struct {
Path string `toml:"path"`
2022-01-17 22:38:56 +00:00
}
func ParseConfig(path string) (Config, error) {
cfg := Config{}
data, _ := os.ReadFile(path)
err := toml.Unmarshal(data, &cfg)
if err != nil {
return Config{}, err
}
return cfg, nil
}