sca_base_module_config

package module
v0.0.0-...-74801d3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 11 Imported by: 7

README

SCA基础配置模块(Base Module Config)

go get -u github.com/scagogogo/sca-base-module-config

Documentation

Index

Constants

View Source
const DefaultConfigName = "config"
View Source
const ScaAutoInitConfigEnvName = "SCA_AUTO_INIT_CONFIG"

Variables

This section is empty.

Functions

func GetEnvBool

func GetEnvBool(name string) *bool

func GetEnvBoolOrDefault

func GetEnvBoolOrDefault(name string, defaultValue bool) bool

func GetEnvInt

func GetEnvInt(name string) *int

func GetEnvIntOrDefault

func GetEnvIntOrDefault(name string, defaultValue int) int

func GetEnvString

func GetEnvString(name string) *string

func GetEnvStringOrDefault

func GetEnvStringOrDefault(name, defaultValue string) string

func InitDefault

func InitDefault() error

InitDefault 初始化默认

func OrDefault

func OrDefault[T any](value, defaultValue T) T

OrDefault 如果给定的值为空的话则返回默认值

Types

type COS

type COS struct {
	Endpoint  string `yaml:"endpoint" mapstructure:"endpoint"`
	SecretId  string `yaml:"secret-id" mapstructure:"secret-id"`
	SecretKey string `yaml:"secret-key" mapstructure:"secret-key"`
}

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 Init

func Init(configName string) (*Configuration, error)

Init 初始化配置文件

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 Database

type Database struct {
	Mysql Mysql `yaml:"mysql" mapstructure:"mysql"`
}

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 LoggerEnable struct {
	Stdout *bool `yaml:"stdout" mapstructure:"stdout"`
	File   *bool `yaml:"file" mapstructure:"file"`
}

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 MysqlConnection struct {
	MaxIdle     *int           `yaml:"max-idle" mapstructure:"max-idle"`
	MaxOpen     *int           `yaml:"max-open" mapstructure:"max-open"`
	MaxLifetime *time.Duration `yaml:"max-lifetime" mapstructure:"max-lifetime"`
}

type MysqlDriverEnable

type MysqlDriverEnable struct {
	SqlX *bool `yaml:"sqlx" mapstructure:"sqlx"`
	Gorm *bool `yaml:"gorm" mapstructure:"gorm"`
}

type OSS

type OSS struct {
	Endpoint        string `yaml:"endpoint" mapstructure:"endpoint"`
	AccessKeyId     string `yaml:"access-key-id" mapstructure:"access-key-id"`
	AccessKeySecret string `yaml:"access-key-secret" mapstructure:"access-key-secret"`
}

type Redis

type Redis struct {
	AutoInit *bool  `yaml:"auto-init"  mapstructure:"auto-init"`
	Address  string `yaml:"address" mapstructure:"address"`
	Passwd   string `yaml:"passwd" mapstructure:"passwd"`
}

func (Redis) IsOk

func (x Redis) IsOk() bool

Jump to

Keyboard shortcuts

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