Documentation
¶
Index ¶
- Constants
- func GetEnvBool(name string) *bool
- func GetEnvBoolOrDefault(name string, defaultValue bool) bool
- func GetEnvInt(name string) *int
- func GetEnvIntOrDefault(name string, defaultValue int) int
- func GetEnvString(name string) *string
- func GetEnvStringOrDefault(name, defaultValue string) string
- func InitDefault() error
- func OrDefault[T any](value, defaultValue T) T
- type COS
- type Configuration
- type Crawler
- type CrawlerConsumer
- type CrawlerProxy
- type CrawlerQueue
- type Database
- type Logger
- type LoggerEnable
- type Mysql
- type MysqlConnection
- type MysqlDriverEnable
- type OSS
- type Redis
Constants ¶
View Source
const DefaultConfigName = "config"
View Source
const ScaAutoInitConfigEnvName = "SCA_AUTO_INIT_CONFIG"
Variables ¶
This section is empty.
Functions ¶
func GetEnvBool ¶
func GetEnvBoolOrDefault ¶
func GetEnvIntOrDefault ¶
func GetEnvString ¶
func GetEnvStringOrDefault ¶
Types ¶
type Configuration ¶
type Configuration struct {
Database Database `yaml:"database" mapstructure:"database"`
Redis Redis `yaml:"redis" mapstructure:"redis"`
Logger Logger `yaml:"logger" mapstructure:"logger"`
OSS OSS `yaml:"oss" mapstructure:"oss"`
COS COS `yaml:"cos" mapstructure:"cos"`
Crawler Crawler `yaml:"crawler" mapstructure:"crawler"`
// 把原来的viper也获取一下放在这里,随时都可以通过viper的方法来获取
*viper.Viper
// 未明确声明的就放在这里吧...
ViperRemainMap map[string]any `mapstructure:",remain"`
}
Configuration 对应着一个映射文件
var Config *Configuration
func (*Configuration) GetStringOrDefault ¶
func (x *Configuration) GetStringOrDefault(name, defaultValue string) string
type Crawler ¶
type Crawler struct {
Proxy CrawlerProxy `yaml:"proxy" mapstructure:"proxy"`
Queue CrawlerQueue `yaml:"queue" mapstructure:"queue"`
Consumer CrawlerConsumer `yaml:"consumer" mapstructure:"consumer"`
}
type CrawlerConsumer ¶
type CrawlerConsumer struct {
WorkerNum int `yaml:"worker-num" mapstructure:"worker-num"`
}
type CrawlerProxy ¶
type CrawlerProxy struct {
// 动态代理
DynamicProxy string `json:"dynamic-proxy" mapstructure:"dynamic-proxy"`
// 提取型短效代理,配置的是一个接口的URL,待认证,对这个接口发送GET请求返回样例如下:
// 1.1.1.1:10086
// 2.3.4.5:10086
// 192.168.178.1:10086
// 198.3.134.156:10086
ShortProxy string `json:"short-proxy" mapstructure:"short-proxy"`
}
CrawlerProxy 代理设置
func (CrawlerProxy) AcquireOneShortProxy ¶
func (x CrawlerProxy) AcquireOneShortProxy(ctx context.Context) (string, error)
AcquireOneShortProxy 尝试获取一个短效代理
func (CrawlerProxy) AcquireShortProxy ¶
func (x CrawlerProxy) AcquireShortProxy(ctx context.Context) ([]string, error)
AcquireShortProxy 尝试提取短效代理
type CrawlerQueue ¶
type CrawlerQueue struct {
Name string `yaml:"name" mapstructure:"name"`
}
type Logger ¶
type Logger struct {
AutoInit *bool `yaml:"auto-init" mapstructure:"auto-init"`
Level string `yaml:"level" mapstructure:"level"`
Enable LoggerEnable `yaml:"enable" mapstructure:"enable"`
Directory string `yaml:"directory" mapstructure:"directory"`
}
type LoggerEnable ¶
type Mysql ¶
type Mysql struct {
// 自动初始化MySQL驱动
AutoInit *bool `yaml:"auto-init" mapstructure:"auto-init"`
// Example: "xxxx:xxxxxxxx@tcp(xxxx)/xxxx?parseTime=true&loc=Local&charset=utf8mb4"
DSN string `yaml:"dsn" mapstructure:"dsn"`
Driver MysqlDriverEnable `yaml:"driver" mapstructure:"driver"`
Connection MysqlConnection `yaml:"connection" mapstructure:"connection"`
}
type MysqlConnection ¶
type MysqlDriverEnable ¶
Click to show internal directories.
Click to hide internal directories.