config

package
v1.23.59 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = CoreConfig{
	MainConf: MainConfig{
		HttpAddr:    ":8080",
		OpenDocsAPI: true,
		Env:         "dev",
	},
	LogsConf: LogsConfig{
		"main": []LogConfig{
			{Level: zapcore.InfoLevel},
		},
		"access": []LogConfig{
			{Level: zapcore.InfoLevel},
		},
	},
}

DefaultConfig 默认配置

Functions

func Env added in v0.1.19

func Env() string

Env 获取环境

func IsDev added in v0.1.19

func IsDev() bool

IsDev 是否开发环境

func IsProd added in v0.1.19

func IsProd() bool

IsProd 是否生产环境

func LoadYamlLocalFile

func LoadYamlLocalFile(file string, cfg interface{}) error

LoadYamlLocalFile .

func LoadYamlReader

func LoadYamlReader(r io.Reader, cfg interface{}) error

LoadYamlReader .

Types

type AliConfig

type AliConfig struct {
	RegionID        string `yaml:"region_id"`
	Endpoint        string `yaml:"endpoint"`
	AccessKeyID     string `yaml:"access_key_id"`
	AccessKeySecret string `yaml:"access_key_secret"`
}

type AliOSSConfig

type AliOSSConfig struct {
	AliConfig
	Bucket string `yaml:"bucket"`
}

AliOSSConfig .

type CoreConfig added in v0.1.7

type CoreConfig struct {
	MainConf MainConfig `yaml:"main"`
	LogsConf LogsConfig `yaml:"logger"`
}

Config 。

func Conf

func Conf() *CoreConfig

Conf .

func LoadCoreConfig added in v0.2.6

func LoadCoreConfig(configPath ...string) (*CoreConfig, error)

LoadCoreConfig 自动获取配置

func LoadCoreConfigFromEnv added in v0.2.1

func LoadCoreConfigFromEnv() (*CoreConfig, error)

LoadCoreConfigFromEnv 通过环境变量获取远程配置 YGCFG_AK YGCFG_SK YGCFG_GROUP YGCFG_KEY

func LoadCoreConfigFromFile added in v0.1.7

func LoadCoreConfigFromFile(filepath string) (*CoreConfig, error)

LoadCoreConfigFromFile .

type ESConfig added in v1.3.24

type ESConfig struct {
	Addresses     []string      `yaml:"addresses"`
	Username      string        `yaml:"username"`
	Password      string        `yaml:"password"`
	MaxRetries    int           `yaml:"max_retries"`    // 最大重试次数
	SlowThreshold time.Duration `yaml:"slow_threshold"` // 慢查询阈值,示例 100ms
}

ESConfig ES配置

type FilePurpose

type FilePurpose = string

type JwtConfig

type JwtConfig struct {
	// Secret jwt secret
	Secret string `yaml:"secret"`
	// Expire jwt expire time
	Expire time.Duration `yaml:"expire"`
}

JwtConfig jwt config

type LLMModelConfig added in v1.3.39

type LLMModelConfig struct {
	Provider    string       `json:"provider" yaml:"provider"`
	APIKEY      string       `json:"api_key" yaml:"api_key"`
	BaseURL     string       `json:"base_url" yaml:"base_url"`
	ModelName   string       `json:"model_name" yaml:"model_name"`
	Proxy       *ProxyConfig `json:"proxy,omitempty" yaml:"proxy,omitempty"`
	Temperature float32      `json:"temperature,omitempty" yaml:"temperature,omitempty"`
	MaxTokens   int          `json:"max_tokens,omitempty" yaml:"max_tokens,omitempty"`
	TopP        float32      `json:"top_p,omitempty" yaml:"top_p,omitempty"`
}

LLMModelConfig holds LLM model selection and parameter options.

type LocalStorageConfig

type LocalStorageConfig struct {
	Dir string `yaml:"dir"`
	// PublicPrefix 公开访问的前缀
	PublicPrefix string `yaml:"public_prefix"`
}

LocalStorageConfig 。

type LogConfig

type LogConfig struct {
	// Writer 日志输出位置 console/file/workwx
	Writer string `yaml:"writer"`
	// Encoder 编码格式
	Encoder string        `yaml:"encoder"`
	Level   zapcore.Level `yaml:"level"`
	Key     string        `yaml:"key,omitempty"`
	// AliyunSLS          *AliyunSLSConfig  `yaml:"aliyun_sls,omitempty"`
	TencentCLS         *TencentCLSConfig `yaml:"tencent_cls,omitempty"`
	*lumberjack.Logger `yaml:",inline"`
}

LogConfig 。

type LogsConfig

type LogsConfig map[string][]LogConfig

LogsConfig 。

func (LogsConfig) Default

func (c LogsConfig) Default() []LogConfig

Default 获取默认日志配置

func (LogsConfig) Get

func (c LogsConfig) Get(name string) []LogConfig

Get 获取日志配置

type MainConfig

type MainConfig struct {
	App         string `yaml:"app"`
	HttpAddr    string `yaml:"http_addr"`
	GrpcAddr    string `yaml:"grpc_addr"`
	OpenDocsAPI bool   `yaml:"open_docs_api"`
	// Deprecated: 1.23.21 use DatabaseConns
	MysqlConns map[string]string `yaml:"mysql_conns"`
	// Deprecated 1.23.21 use DatabaseConns
	PostgresConns   map[string]string `yaml:"postgres_conns"`
	DatabaseConns   map[string]string `yaml:"database_conns"`
	ClickhouseConns map[string]string `yaml:"clickhouse_conns"`
	Env             string            `yaml:"env"`
}

MainConfig 住配置

type MinossConfig added in v0.4.10

type MinossConfig struct {
	EndPoint        string `yaml:"end_point"`
	AccessKeyID     string `yaml:"access_key_id"`
	SecretAccessKey string `yaml:"secret_access_key"`
	// UseSSL          bool   `yaml:"use_ssl"`
	Bucket string `yaml:"bucket"`
}

MinossConfig Minoss存储配置

type MysqlConfig added in v1.23.1

type MysqlConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Database string `yaml:"database"`
	Charset  string `yaml:"charset"`
}

MysqlConfig 数据库连接配置结构体

func (*MysqlConfig) BuildDNS added in v1.23.1

func (cfg *MysqlConfig) BuildDNS() string

BuildDNS 方法用于生成 DSN (Data Source Name)

type NotifyConfig

type NotifyConfig struct {
	// SMTP 发邮件参数
	SMTPs     []*SMTPConfig `yaml:"smtps"`
	WecomApps WecomApps     `yaml:"wecom_apps"`
}

func (NotifyConfig) WecomApp

func (c NotifyConfig) WecomApp(name string) WecomApp

WecomApp 企业微信应用

type ProxyConfig

type ProxyConfig struct {
	Scheme   string `yaml:"scheme"`
	Addr     string `yaml:"addr"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

ProxyConfig holds proxy connection settings including scheme, address, and credentials.

type RabbitMQConfig added in v1.3.58

type RabbitMQConfig struct {
	URL          string `yaml:"url"`
	ExchangeName string `yaml:"exchange_name"`
	ExchangeType string `yaml:"exchange_type"`
	QueueName    string `yaml:"queue_name"`
	RoutingKey   string `yaml:"routing_key"`
}

RabbitMQConfig 配置结构体

type RedisConfig added in v0.1.21

type RedisConfig struct {
	Addr     string `yaml:"addr" json:"addr"`
	Password string `yaml:"password" json:"password"`
	DB       int    `yaml:"db" json:"db"`
}

RedisConfig redis 连接属性

type S3StorageConfig added in v1.3.31

type S3StorageConfig struct {
	EndPoint        string `yaml:"end_point"`
	AccessKeyID     string `yaml:"access_key_id"`
	SecretAccessKey string `yaml:"secret_access_key"`
	Region          string `yaml:"region"`
	Bucket          string `yaml:"bucket"`
	UsePathStyle    bool   `yaml:"use_path_style"` // 是否使用路径风格的URL minio true 腾讯云 false
}

S3StorageConfig S3通用存储

type SMSConfig

type SMSConfig struct {
	// Aliyun 阿里云短信
	Aliyun       *AliConfig        `yaml:"aliyun"`
	Tencent      *TencentSMSConfig `yaml:"tencent"`
	SignName     string            `yaml:"sign_name"`
	TemplateCode string            `yaml:"template_code"`
}

type SMTPConfig

type SMTPConfig struct {
	Name     string `yaml:"name"`
	Addr     string `yaml:"addr"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Nickname string `yaml:"nickname"`
}

SMTPConfig 发邮件参数

type ServiceInfo added in v0.2.3

type ServiceInfo struct {
	// Name 服务名称, 用于标识服务, 例如: mysql, redis
	Name string `yaml:"name"`
	// Cap 服务容量
	Cap int `yaml:"cap"`
}

ServiceInfo 服务信息

type ServicePoolConfig added in v0.2.3

type ServicePoolConfig struct {
	// Services 服务配置
	Services []ServiceInfo `yaml:"services"`
	// Expire 服务过期时间
	Expire time.Duration `yaml:"expire"`
	// Version 服务版本
	Version string `yaml:"version"`
}

ServicePoolConfig 服务池配置

type StorageConfig

type StorageConfig struct {
	StorageOption `yaml:",inline"`

	Local   *LocalStorageConfig `yaml:"local,omitempty"`
	AliOSS  *AliOSSConfig       `yaml:"alioss,omitempty"`
	UpYun   *UpYunConfig        `yaml:"upyun,omitempty"`
	Tencent *TencentCOSConfig   `yaml:"tencent,omitempty"`
	Minoss  *MinossConfig       `yaml:"minoss,omitempty"`
	S3      *S3StorageConfig    `yaml:"s3,omitempty"`
}

StorageConfig 对象存储配置

type StorageOption

type StorageOption struct {
	// Purpose 是文件的用途,按业务分类
	Purpose FilePurpose `yaml:"purpose"`
	// PresignedTimeout 预签名超时时间
	PresignedTimeout time.Duration `yaml:"presigned_timeout"`
}

StorageOption 对象存储通用配置选项

type TencentCLSConfig added in v0.1.3

type TencentCLSConfig struct {
	TencentConfig `yaml:",inline"`

	TopicID string `yaml:"topic_id"`
}

TencentCLSConfig 腾讯云日志服务配置

type TencentCOSConfig

type TencentCOSConfig struct {
	TencentConfig `yaml:",inline"`
	Bucket        string `yaml:"bucket"`
}

TencentCOSConfig 腾讯云对象存储配置

type TencentConfig

type TencentConfig struct {
	SecretID  string `yaml:"secret_id"`
	SecretKey string `yaml:"secret_key"`
	Region    string `yaml:"region"`
	Endpoint  string `yaml:"endpoint"`
}

TencentConfig 腾讯云配置

type TencentSMSConfig added in v0.4.22

type TencentSMSConfig struct {
	TencentConfig `yaml:",inline"`
	SmsSdkAppId   string `yaml:"sms_sdk_app_id"`
}

TencentCOSConfig 腾讯云对象存储配置

type UpYunConfig

type UpYunConfig struct {
	Bucket   string `yaml:"bucket"`
	Operator string `yaml:"operator"`
	Password string `yaml:"password"`
}

UpYunConfig .

type WechatOfficialAccountConfig added in v0.1.25

type WechatOfficialAccountConfig struct {
	offConfig.Config `yaml:",inline"`

	Templates map[string]string `yaml:"templates"`
}

WechatOfficialAccountConfig 微信公众号配置

type WecomApp

type WecomApp struct {
	Name           string `json:"name" yaml:"name"`
	CompanyID      string `json:"company_id" yaml:"company_id"`
	AgentID        int64  `json:"agent_id" yaml:"agent_id"`
	Secret         string `json:"secret" yaml:"secret"`
	Token          string `json:"token" yaml:"token"`
	EncodingAESKey string `json:"encoding_aes_key" yaml:"encoding_aes_key"`
}

WecomApp 企业微信应用

func (WecomApp) AESKey

func (cs WecomApp) AESKey() []byte

func (WecomApp) IsValide

func (c WecomApp) IsValide() bool

IsValide 是否有效

type WecomApps

type WecomApps []WecomApp

WecomApps 企业微信应用列表

type WecomConfig

type WecomConfig struct {
	Apps WecomApps `yaml:"apps"`
}

func (WecomConfig) WecomApp

func (c WecomConfig) WecomApp(name string) WecomApp

WecomApp 企业微信应用

Jump to

Keyboard shortcuts

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