tstor/config/model.go

75 lines
1.6 KiB
Go
Raw Normal View History

package config
// Root is the main yaml config object
type Root struct {
2021-04-04 17:24:58 +00:00
HTTPGlobal *HTTPGlobal `yaml:"http"`
WebDAV *WebDAVGlobal `yaml:"webdav"`
Torrent *TorrentGlobal `yaml:"torrent"`
Fuse *FuseGlobal `yaml:"fuse"`
2021-11-20 19:57:25 +00:00
Log *Log `yaml:"log"`
2021-04-04 17:24:58 +00:00
Routes []*Route `yaml:"routes"`
2021-03-01 18:04:59 +00:00
}
2021-11-20 19:57:25 +00:00
type Log struct {
Debug bool `yaml:"debug"`
MaxBackups int `yaml:"max_backups"`
MaxSize int `yaml:"max_size"`
MaxAge int `yaml:"max_age"`
Path string `yaml:"path"`
}
2021-04-04 17:24:58 +00:00
type TorrentGlobal struct {
2021-11-20 19:57:25 +00:00
AddTimeout int `yaml:"add_timeout,omitempty"`
2021-04-04 17:24:58 +00:00
GlobalCacheSize int64 `yaml:"global_cache_size,omitempty"`
MetadataFolder string `yaml:"metadata_folder,omitempty"`
DisableIPv6 bool `yaml:"disable_ipv6,omitempty"`
}
type WebDAVGlobal struct {
Port int `yaml:"port"`
User string `yaml:"user"`
Pass string `yaml:"pass"`
2021-04-04 17:24:58 +00:00
}
type HTTPGlobal struct {
Port int `yaml:"port"`
}
type FuseGlobal struct {
AllowOther bool `yaml:"allow_other,omitempty"`
Path string `yaml:"path"`
}
2021-04-04 17:24:58 +00:00
type Route struct {
Name string `yaml:"name"`
2021-03-01 18:04:59 +00:00
Torrents []*Torrent `yaml:"torrents"`
}
type Torrent struct {
2021-04-04 17:24:58 +00:00
MagnetURI string `yaml:"magnet_uri,omitempty"`
TorrentPath string `yaml:"torrent_path,omitempty"`
}
func AddDefaults(r *Root) *Root {
2021-04-04 17:24:58 +00:00
if r.Torrent == nil {
r.Torrent = &TorrentGlobal{}
}
if r.Torrent.GlobalCacheSize == 0 {
r.Torrent.GlobalCacheSize = 1024 // 1GB
}
if r.Torrent.MetadataFolder == "" {
r.Torrent.MetadataFolder = metadataFolder
}
if r.Fuse == nil {
r.Fuse = &FuseGlobal{}
}
2021-04-04 17:24:58 +00:00
if r.Fuse.Path == "" {
r.Fuse.Path = mountFolder
}
return r
}