config

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(configPath string) error

LoadConfig 加载配置文件

Types

type Config

type Config struct {
	Server    ServerConfig    `mapstructure:"server"`
	Redis     RedisConfig     `mapstructure:"redis"`
	Validator ValidatorConfig `mapstructure:"validator"`
	Crawler   CrawlerConfig   `mapstructure:"crawler"`
	Log       LogConfig       `mapstructure:"log"`
	Security  SecurityConfig  `mapstructure:"security"`
}
var (
	GlobalConfig Config
)

func (*Config) GetCheckInterval

func (c *Config) GetCheckInterval() time.Duration

func (*Config) GetCrawlerInterval

func (c *Config) GetCrawlerInterval() time.Duration

func (*Config) GetRedisAddr

func (c *Config) GetRedisAddr() string

Helper functions for getting config values

func (*Config) GetValidatorTimeout

func (c *Config) GetValidatorTimeout() time.Duration

type CrawlerConfig

type CrawlerConfig struct {
	Interval  int `mapstructure:"interval"`
	BatchSize int `mapstructure:"batch_size"`
}

type LogConfig

type LogConfig struct {
	Level    string `mapstructure:"level"`
	Output   string `mapstructure:"output"`
	FilePath string `mapstructure:"file_path"`
}

type RedisConfig

type RedisConfig struct {
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`
}

type SecurityConfig

type SecurityConfig struct {
	// 基本认证
	AuthEnabled bool   `mapstructure:"auth_enabled"`
	Username    string `mapstructure:"username"`
	Password    string `mapstructure:"password"`

	// API Key认证
	APIKeyEnabled bool     `mapstructure:"api_key_enabled"`
	APIKeys       []string `mapstructure:"api_keys"`

	// 限流配置
	RateLimit        int  `mapstructure:"rate_limit"`         // 每个时间窗口最大请求数
	RateWindow       int  `mapstructure:"rate_window"`        // 时间窗口(分钟)
	BanDuration      int  `mapstructure:"ban_duration"`       // 封禁时长(小时)
	RateLimitEnabled bool `mapstructure:"rate_limit_enabled"` // 是否启用限流
}

SecurityConfig 安全配置

type ServerConfig

type ServerConfig struct {
	Port int    `mapstructure:"port"`
	Mode string `mapstructure:"mode"`
}

type ValidatorConfig

type ValidatorConfig struct {
	Timeout       int    `mapstructure:"timeout"`
	CheckInterval int    `mapstructure:"check_interval"`
	TestURL       string `mapstructure:"test_url"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL