refactor: rewrite project from Rust to Go
- Replace Axum with Chi router - Replace sqlx with pgx for PostgreSQL - Replace tonic/prost with grpc-go - Replace tracing with zerolog - Update flake.nix for Go build with protoc generation - Preserve all existing endpoints and functionality Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App AppConfig `yaml:"app"`
|
||||
Database DatabaseConfig `yaml:"database"`
|
||||
Metadata MetadataConfig `yaml:"metadata"`
|
||||
Indexers []IndexerConfig `yaml:"indexers"`
|
||||
Torrent TorrentConfig `yaml:"torrent"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Port int `yaml:"port"`
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
URL string `yaml:"url"`
|
||||
}
|
||||
|
||||
type MetadataConfig struct {
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
}
|
||||
|
||||
type IndexerType string
|
||||
|
||||
const (
|
||||
IndexerTypeJackett IndexerType = "jackett"
|
||||
IndexerTypeProwlarr IndexerType = "prowlarr"
|
||||
IndexerTypeTorznab IndexerType = "torznab"
|
||||
)
|
||||
|
||||
type IndexerConfig struct {
|
||||
Name string `yaml:"name"`
|
||||
IndexerType IndexerType `yaml:"indexer_type"`
|
||||
URL string `yaml:"url"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
}
|
||||
|
||||
type TorrentClientType string
|
||||
|
||||
const (
|
||||
TorrentClientQBittorrent TorrentClientType = "qbittorrent"
|
||||
TorrentClientStub TorrentClientType = "stub"
|
||||
TorrentClientNone TorrentClientType = "none"
|
||||
)
|
||||
|
||||
type TorrentConfig struct {
|
||||
ClientType TorrentClientType `yaml:"client_type"`
|
||||
URL string `yaml:"url,omitempty"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
LogPath string `yaml:"log_path,omitempty"`
|
||||
SavePath string `yaml:"save_path,omitempty"`
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read config file: %w", err)
|
||||
}
|
||||
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse config: %w", err)
|
||||
}
|
||||
|
||||
if cfg.App.Port == 0 {
|
||||
cfg.App.Port = 3000
|
||||
}
|
||||
|
||||
for i := range cfg.Indexers {
|
||||
if cfg.Indexers[i].IndexerType == "" {
|
||||
cfg.Indexers[i].IndexerType = IndexerTypeJackett
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Torrent.ClientType == "" {
|
||||
cfg.Torrent.ClientType = TorrentClientNone
|
||||
}
|
||||
|
||||
if cfg.Torrent.SavePath == "" {
|
||||
cfg.Torrent.SavePath = "/tmp/downloads"
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user