12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package config
- import (
- "fmt"
- "os"
- "gopkg.in/yaml.v3"
- )
- type Config struct {
- Server ServerConfig `yaml:"server"`
- Database DatabaseConfig `yaml:"database"`
- Social SocialConfig `yaml:"social"`
- Google GoogleConfig `yaml:"google"`
- LiteLLM LiteLLMConfig `yaml:"litellm"`
- }
- type ServerConfig struct {
- ListeningPort int `yaml:"listening_port"`
- TLS TLSConfig `yaml:"tls"`
- CorsOrigins []string `yaml:"cors_origins"`
- }
- type TLSConfig struct {
- Enabled bool `yaml:"enabled"`
- CertFile string `yaml:"cert_file"`
- KeyFile string `yaml:"key_file"`
- }
- type DatabaseConfig struct {
- Path string `yaml:"path"`
- MaxOpenConns int `yaml:"max_open_conns"`
- MaxIdleConns int `yaml:"max_idle_conns"`
- ConnMaxLifetime int `yaml:"conn_max_lifetime"`
- }
- type JWTConfig struct {
- JwtSecret string `yaml:"jwt_secret"`
- }
- type SocialConfig struct {
- Instagram InstagramConfig `yaml:"instagram"`
- TikTok TikTokConfig `yaml:"tiktok"`
- YouTube YouTubeConfig `yaml:"youtube"`
- }
- type InstagramConfig struct {
- APIKey string `yaml:"api_key"`
- BaseURL string `yaml:"base_url"`
- }
- type TikTokConfig struct {
- APIKey string `yaml:"api_key"`
- BaseURL string `yaml:"base_url"`
- }
- type YouTubeConfig struct {
- APIKey string `yaml:"api_key"`
- BaseURL string `yaml:"base_url"`
- }
- type GoogleConfig struct {
- TrendsAPIKey string `yaml:"trends_api_key"`
- BaseURL string `yaml:"base_url"`
- }
- type LiteLLMConfig struct {
- ProxyURL string `yaml:"proxy_url"`
- APIKey string `yaml:"api_key"`
- Model string `yaml:"model"`
- Headers map[string]string `yaml:"headers"`
- MaxRetries int `yaml:"max_retries"`
- TimeoutSecs int `yaml:"timeout_secs"`
- }
- func Load(path string) (*Config, error) {
- data, err := os.ReadFile(path)
- if err != nil {
- return nil, fmt.Errorf("read config file: %w", err)
- }
- var config Config
- if err := yaml.Unmarshal(data, &config); err != nil {
- return nil, fmt.Errorf("parse config file: %w", err)
- }
- return &config, nil
- }
|