config.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "gopkg.in/yaml.v3"
  6. )
  7. type Config struct {
  8. Server ServerConfig `yaml:"server"`
  9. Database DatabaseConfig `yaml:"database"`
  10. Social SocialConfig `yaml:"social"`
  11. Google GoogleConfig `yaml:"google"`
  12. LiteLLM LiteLLMConfig `yaml:"litellm"`
  13. }
  14. type ServerConfig struct {
  15. ListeningPort int `yaml:"listening_port"`
  16. TLS TLSConfig `yaml:"tls"`
  17. CorsOrigins []string `yaml:"cors_origins"`
  18. }
  19. type TLSConfig struct {
  20. Enabled bool `yaml:"enabled"`
  21. CertFile string `yaml:"cert_file"`
  22. KeyFile string `yaml:"key_file"`
  23. }
  24. type DatabaseConfig struct {
  25. Path string `yaml:"path"`
  26. MaxOpenConns int `yaml:"max_open_conns"`
  27. MaxIdleConns int `yaml:"max_idle_conns"`
  28. ConnMaxLifetime int `yaml:"conn_max_lifetime"`
  29. }
  30. type JWTConfig struct {
  31. JwtSecret string `yaml:"jwt_secret"`
  32. }
  33. type SocialConfig struct {
  34. Instagram InstagramConfig `yaml:"instagram"`
  35. TikTok TikTokConfig `yaml:"tiktok"`
  36. YouTube YouTubeConfig `yaml:"youtube"`
  37. }
  38. type InstagramConfig struct {
  39. APIKey string `yaml:"api_key"`
  40. BaseURL string `yaml:"base_url"`
  41. }
  42. type TikTokConfig struct {
  43. APIKey string `yaml:"api_key"`
  44. BaseURL string `yaml:"base_url"`
  45. }
  46. type YouTubeConfig struct {
  47. APIKey string `yaml:"api_key"`
  48. BaseURL string `yaml:"base_url"`
  49. }
  50. type GoogleConfig struct {
  51. TrendsAPIKey string `yaml:"trends_api_key"`
  52. BaseURL string `yaml:"base_url"`
  53. }
  54. type LiteLLMConfig struct {
  55. ProxyURL string `yaml:"proxy_url"`
  56. APIKey string `yaml:"api_key"`
  57. Model string `yaml:"model"`
  58. Headers map[string]string `yaml:"headers"`
  59. MaxRetries int `yaml:"max_retries"`
  60. TimeoutSecs int `yaml:"timeout_secs"`
  61. }
  62. func Load(path string) (*Config, error) {
  63. data, err := os.ReadFile(path)
  64. if err != nil {
  65. return nil, fmt.Errorf("read config file: %w", err)
  66. }
  67. var config Config
  68. if err := yaml.Unmarshal(data, &config); err != nil {
  69. return nil, fmt.Errorf("parse config file: %w", err)
  70. }
  71. return &config, nil
  72. }