Documentation
¶
Index ¶
- Constants
- Variables
- func GetDataSource(args any) error
- func GetDataSourceBody(params DataSourceArgs) (string, error)
- func GetDataSourceWithCheck(params DataSourceArgs, shouldUpdate func([]byte) (bool, error)) error
- func GetDevName(name string) string
- func GetEnvFiles() []string
- func GetNodeIPFromAPIs(ipapi string, timeout ...time.Duration) string
- func InitTester()
- func IsSkipRemoteConfig() bool
- func LoadConfig() error
- func ParseDuration(s string, defDur time.Duration, minDur ...time.Duration) (time.Duration, error)
- func ParseRemoteFileConfig(cfg *FilesConf, secret string) error
- func StopTester()
- type DataSourceArgs
- type FilesConf
- type LogConf
- type M
- type MainConf
- type NodeConf
- type NodeInfo
- type RespDataSource
- type SYSConf
- type WebConf
Constants ¶
View Source
const UnknownNodeType = -1
UnknownNodeType 未知节点类型
Variables ¶
View Source
var ( // AlarmOn 全局报警开关 (区别是否被排除报警, 如测试节点) AlarmOn atomic.Bool // Whitelist 接口 IP 白名单配置 Whitelist map[*net.IPNet]int64 // Blacklist 接口 IP 黑名单配置 Blacklist map[*net.IPNet]int64 )
View Source
var ( // BinName !!! 这个变量决定启动时加载的默认配置名, 日志名等 // 可以由 LDFLAGS 编译时注入 // 可以在应用程序 func init() { BinName = "yourapp" ... } // 也可启动程序时命令行参数指定主配置文件 BinName = "ffapp" AppName = "FF.App" // DebName !!! 这个变量决定自升级时安装命令, 以及日志中显示的包名称 // 可以在应用程序 func init() { DebName = "your-app" ... } DebName = "ff-app" // BinNameEnvName 上面 3 个变量可以在环境变量中设置(优先使用): LOCAL_DEB_NAME=your-web-app BinNameEnvName = "LOCAL_BIN_NAME" AppNameEnvName = "LOCAL_APP_NAME" DebNameEnvName = "LOCAL_DEB_NAME" // AppBaseSecretValue APP 设置的基础密钥值(可选, 优先使用) AppBaseSecretValue string // AppConfigBody APP 设置的固定配置 JSON 字符串, 替代配置文件 (可选, 优先使用) AppConfigBody []byte // ConfigInitialized 全局配置是否已初始化 ConfigInitialized bool )
View Source
var ( // RootPath 程序运行绝对路径 !!! 决定加载的默认配置目录, 环境文件目录, 日志目录(必须存在) RootPath string DefaultRootPath = utils.ExecutableDir(true) DefaultLogPath = filepath.Join(DefaultRootPath, "..", "log") // LogDaemon 守护进程日志, 路径为空时不记录日志 LogDaemon = filepath.Join(DefaultLogPath, "daemon.log") // LogPath 日志路径 LogPath string LogFile string // ConfigPath 主配置文件绝对路径, .env 配置文件路径 ConfigPath string ConfigFile string EnvFilePath string EnvMainFile string // WhitelistConfigFile IP 白名单配置文件路径 WhitelistConfigFile string DefaultWhitelistConfigFile string // BlacklistConfigFile IP 黑名单配置文件路径 BlacklistConfigFile string DefaultBlacklistConfigFile string // ReqUserAgent Request 请求名称 ReqUserAgent string )
View Source
var ( Debug bool // LogLevel 日志级别: -1Trace 0Debug 1Info 2Warn(默认) 3Error 4Fatal 5Panic 6NoLevel 7Off LogLevel = 2 // LogSamplePeriodDur 抽样日志设置 (每秒最多 10 个日志) LogSamplePeriodDur = time.Second LogSampleBurst = 10 // LogFileMaxSize 每 100M 自动切割, 保留 30 天内最近 10 个日志文件 LogFileMaxSize = 100 LogFileMaxBackups = 10 LogFileMaxAge = 30 // LogPostIntervalDuration 日志推送时间间隔(秒) LogPostIntervalDuration = 2 * time.Second // LogPostBatchNum 单次批量提交数据最大条数或最大字节数 LogPostBatchNum = 2000 LogPostBatchBytes = 2 << 20 // BaseSecretValue 项目基础密钥值(从环境变量解码), 与 config.Config().SYSConf.BaseSecretValue 相同 BaseSecretValue string // BaseSecretEnvName 项目基础密钥 (环境变量名) BaseSecretEnvName = "BASE_SECRET_KEY" // BaseSecretKeyNameEnvName 用于在环境变量中指定上一行设置的值的键名, 而不是使用默认的: BASE_SECRET_KEY BaseSecretKeyNameEnvName = "BASE_SECRET_KEY_NAME" // BaseSecretSalt 用于解密基础密钥值的密钥的前半部分, 盐 (编译在程序中), 后半部分为 AppName 值 BaseSecretSalt = "Fufu↑777發彡 " // #nosec G101 // BaseSecretSaltEnvName 环境变量中读取上一行设置的值的键名, 而不是使用上一行中设置的固定值 BaseSecretSaltEnvName = "BASE_SECRET_SALT" // BaseSecretKeyValue 用于解密基础密钥的完整密钥, 默认为: 上面的盐 + AppName 值 // 可由应用自行指定该值以跳过上面的规则, 如在 main.go 中: config.BaseSecretKeyValue = "我的基础密钥解密KEY值" BaseSecretKeyValue string // WatcherIntervalDuration 文件变化监控时间间隔 WatcherIntervalDuration = 2 * time.Minute // DefaultLoadConfigInterval 通用配置定时加载时间, 各类 Sender 运行中加载最新配置 DefaultLoadConfigInterval = 1 * time.Minute // DefaultRandomWait 执行前随机等待最大秒数 DefaultRandomWait = 120 // ReqTimeoutDuration 作为客户端发起请求默认超时时间 ReqTimeoutDuration = 30 * time.Second ReqTimeoutShortDuration = 3 * time.Second // ChanxInitCap 无限缓冲信道默认初始化缓冲大小 ChanxInitCap = 50 // ChanxMaxBufCap 无限缓冲信道最大缓冲数量, 0 为无限, 超过限制(ChanxInitCap + ChanxMaxBufCap)丢弃数据 ChanxMaxBufCap = 500000 // ServiceNameSuffix systemctl 服务名后缀 (Ubuntu) ServiceNameSuffix = ".service" // AlarmDisabledValue 禁用报警标识 AlarmDisabledValue = "--disabled" )
View Source
var ( // WebServerAddr 缺省的 HTTP 接口端口 WebServerAddr = ":12366" // WebServerHttpsAddr 缺省的 HTTPS 接口端口 WebServerHttpsAddr = ":12377" // WebCertFileEnvName 默认证书路径环境变量名 WebCertFileEnvName = "WEB_CERT_FILE" WebKeyFileEnvName = "WEB_KEY_FILE" // WebSignKeyEnvName 接口签名密钥加密串环境变量名 WebSignKeyEnvName = "WEB_SIGN_KEY" // WebSignTTLDefault 接口签名有效生命周期(秒数, 默认: 60, 最小 5) WebSignTTLDefault = 60 WebSignTTLMin = 5 // WebLogInfoKey 接口日志附带请求信息, 上下文键名 WebLogInfoKey = "_WLIK_" // WebLogSlowResponse 慢日志条件 WebLogSlowResponse = 5 * time.Second // WebLogMinStatusCode Web 日志响应码条件值 WebLogMinStatusCode = 500 // WebTimeout Web 请求超时 WebTimeout = 30 * time.Second // WebBodyLimit POST 最大 8M, 超过该值影响: 413 Request Entity Too Large WebBodyLimit = 8 << 20 // WebTokenSalt 用于加密代理客户端请求 IP 的盐, 默认为 BaseSecretValue 项目基础密钥值 WebTokenSalt string )
View Source
var ( // NodeInfoFile 配置中指定的节点基本信息配置文件路径 NodeInfoFile string // NodeInfoBackupFile 节点基本信息备份文件路径 NodeInfoBackupFile string // NodeIPFromAPI 已获取成功的节点 IP NodeIPFromAPI = "" )
View Source
var ( // DefaultTimeZone 默认时区名称, 固定为: UTC+8 DefaultTimeZone = utils.ChinaTimeZone // DefaultTimeLocation 默认时区, 固定为中国时区 DefaultTimeLocation *time.Location // ZeroTimeCST 中国时区 0 值 ZeroTimeCST time.Time ZeroTimeUTC time.Time )
View Source
var ( Version = "0.0.1" GoVersion = "" GitCommit = "" // DebVersion 当前的包版本信息 DebVersion = "" )
View Source
var DefaultGOMAXPROCS = utils.MaxInt(runtime.NumCPU(), 4)
DefaultGOMAXPROCS 缺省的并发配置, 最少 4
Functions ¶
func GetDataSource ¶
GetDataSource 获取源数据配置并更新本地文件 可在应用级重定义该函数, 覆盖 common.Funcs["GetDataSource"]
func GetDataSourceBody ¶ added in v0.1.1
func GetDataSourceBody(params DataSourceArgs) (string, error)
GetDataSourceBody 获取数据源内容
func GetDataSourceWithCheck ¶ added in v1.0.0
func GetDataSourceWithCheck(params DataSourceArgs, shouldUpdate func([]byte) (bool, error)) error
GetDataSourceWithCheck 获取数据源并根据检查结果更新本地文件
func GetNodeIPFromAPIs ¶ added in v0.5.5
GetNodeIPFromAPIs 同时请求多个 API, 返回 IP 结果
func InitTester ¶ added in v0.10.7
func InitTester()
func ParseDuration ¶ added in v0.2.0
ParseDuration 解析时间间隔字符串
func ParseRemoteFileConfig ¶ added in v0.2.0
ParseRemoteFileConfig 解析远端配置获取配置项
func StopTester ¶ added in v0.10.7
func StopTester()
Types ¶
type DataSourceArgs ¶
type LogConf ¶
type LogConf struct {
NoColor bool `json:"no_color"`
NoPretty bool `json:"no_pretty"`
Level int `json:"level"`
File string `json:"file"`
Period uint32 `json:"period"`
Burst uint32 `json:"burst"`
MaxSize int64 `json:"max_size"`
MaxBackups int `json:"max_backups"`
MaxAge int `json:"max_age"`
PostAPI string `json:"post_api"`
PostAPIEnv string `json:"post_api_env"`
PostAlarmAPI string `json:"post_alarm_api"`
PostAlarmAPIEnv string `json:"post_alarm_api_env"`
AlarmCode string `json:"alarm_code"`
AlarmCodeEnv string `json:"alarm_code_env"`
PostInterval int `json:"post_interval"`
PostBatchNum int `json:"post_batch_num"`
PostBatchMB int `json:"post_batch_mb"`
PeriodDuration time.Duration
PostIntervalDuration time.Duration
PostBatchBytes int
}
type MainConf ¶
type MainConf struct {
SYSConf SYSConf `json:"sys_conf"`
MainConf FilesConf `json:"main_conf"`
LogConf LogConf `json:"log_conf"`
NodeConf NodeConf `json:"node_conf"`
WebConf WebConf `json:"web_conf"`
Whitelist []string `json:"whitelist"`
Blacklist []string `json:"blacklist"`
WhitelistConf FilesConf `json:"whitelist_conf"`
BlacklistConf FilesConf `json:"blacklist_conf"`
}
MainConf 接口配置
type NodeInfo ¶
type NodeInfo struct {
// 主机名和网卡 IP
Hostname string `json:"hostname"`
HostIP string `json:"host_ip"`
NodeID int `json:"node_id"`
NodeIP string `json:"service_ip"`
NodeName string `json:"node_name"`
NodeDesc string `json:"node_desc"`
NodeType int `json:"node_type"`
}
NodeInfo 节点信息
type RespDataSource ¶ added in v0.1.1
type RespDataSource struct {
OK int `json:"ok"`
Msg string `json:"msg"`
Data []map[string]any `json:"data"`
}
RespDataSource 数据源响应结构体
type SYSConf ¶
type SYSConf struct {
RestartMain bool `json:"restart_main"`
TimeSyncType string `json:"time_sync_type"`
WatcherInterval string `json:"watcher_interval"`
ReqDebug bool `json:"req_debug"`
ReqTimeout string `json:"req_timeout"`
ReqMaxRetries int `json:"req_max_retries"`
DebVersion string `json:"deb_version"`
CanaryDeployment uint64 `json:"canary_deployment"`
SkipRemoteConfig string `json:"skip_remote_config"`
EnvFiles []string `json:"env_files"`
BaseSecretValue string `json:"-"`
WatcherIntervalDuration time.Duration
ReqTimeoutDuration time.Duration
}
SYSConf 主配置, 变量意义见配置文件中的描述及 default.go 中的默认值
type WebConf ¶ added in v0.0.4
type WebConf struct {
PProfAddr string `json:"pprof_addr"`
ServerAddr string `json:"server_addr"`
ServerHttpsAddr string `json:"server_https_addr"`
StatsPath string `json:"stats_path"`
TrustedProxies []string `json:"trusted_proxies"`
// Gin
TrustedPlatform string `json:"trusted_platform"`
// Fiber
EnableTrustedProxyCheck bool `json:"enable_trusted_proxy_check"`
ProxyHeader string `json:"proxy_header"`
// Fiber 默认不减少内存占用, 这里改为默认减少内存占用(可能增加 CPU 占用)
DisableReduceMemoryUsage bool `json:"disable_reduce_memory_usage"`
// Fiber 短连接模式
DisableKeepalive bool `json:"disable_keepalive"`
// Fiber 请求体大小限制, 0 为默认: 8 * 1024 * 1024, -1 表示不限制
BodyLimit int `json:"body_limit"`
// 黑白名单中间件缓存容量配置, 键生命周期秒数
WhitelistLRUCapacity uint32 `json:"whitelist_lru_capacity"`
WhitelistLRULifetime uint32 `json:"whitelist_lru_lifetime"`
BlacklistLRUCapacity uint32 `json:"blacklist_lru_capacity"`
BlacklistLRULifetime uint32 `json:"blacklist_lru_lifetime"`
// 同时处理的请求数限制, 调用该中间件时有效 (以 处理中 的请求为依据, -1 表示不限制)
RequestsLimit int32 `json:"requests_limit"`
// 接口签名密钥生命周期和签名密钥值
SignTTL int64 `json:"sign_ttl"`
SignKey string `json:"-"`
CertFile string `json:"-"`
KeyFile string `json:"-"`
}
Click to show internal directories.
Click to hide internal directories.