Files
music-agregator/internal/config/config.go
T
2026-05-06 22:53:55 +02:00

61 lines
1.1 KiB
Go

package config
import (
"fmt"
)
const (
IndexerTypeJackett IndexerType = "jackett"
)
const (
TorrentClientQbittorrent TorrentClientType = "qbittorrent"
)
type IndexerType string
type TorrentClientType string
type Config struct {
App struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
} `yaml:"app"`
Indexer struct {
Url string `yaml:"url"`
Port string `yaml:"port"`
Type IndexerType `yaml:"type"`
ApiKey string `yaml:"api_key"`
} `yaml:"indexer"`
Torrent struct {
ClientType TorrentClientType `yaml:"client_type"`
Url string `yaml:"url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"torrent"`
}
func (t *IndexerType) UnmarshalYAML(unmarshal func(any) error) error {
var value string
if err := unmarshal(&value); err != nil {
return err
}
switch IndexerType(value) {
case IndexerTypeJackett:
*t = IndexerType(value)
return nil
default:
return fmt.Errorf("unknown indexer type: %s", value)
}
}
func NewConfig() *Config {
config := Config{}
config.App.Host = "localhost"
config.App.Port = "8080"
return &config
}