config

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownNodeType 未知节点类型
	UnknownNodeType = -1
)

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 = "ff-app"
)
View Source
var (
	// RootPath 程序运行绝对路径 !!! 决定加载的默认配置目录, 环境文件目录, 日志目录
	RootPath        string
	DefaultRootPath = utils.ExecutableDir(true)

	// LogPath 日志路径
	LogPath   string
	LogFile   string
	LogDaemon 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

	// BaseSecretKeyName 项目基础密钥 (环境变量名)
	BaseSecretKeyName = "BASE_SECRET_KEY"
	// BaseSecretKeyNameKeyName 用于在环境变量中指定上一行设置的值的键名, 而不是使用默认的: BASE_SECRET_KEY
	BaseSecretKeyNameKeyName = "BASE_SECRET_KEY_NAME"

	// BaseSecretSalt 用于解密基础密钥值的密钥的前半部分, 盐 (编译在程序中), 后半部分为 AppName 值
	BaseSecretSalt = "Fufu↑777發彡 "
	// BaseSecretSaltKeyName 环境变量中读取上一行设置的值的键名, 而不是使用上一行中设置的固定值
	BaseSecretSaltKeyName = "BASE_SECRET_SALT"

	// 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 = 100000

	// ServiceNameSuffix systemctl 服务名后缀 (Ubuntu)
	ServiceNameSuffix = ".service"
)
View Source
var (
	// WebServerAddr 缺省的 HTTP 接口端口
	WebServerAddr = ":12366"
	// WebServerHttpsAddr 缺省的 HTTPS 接口端口
	WebServerHttpsAddr = ":12377"

	// WebCertFileEnv 默认证书路径环境变量
	WebCertFileEnv = "WEB_CERT_FILE"
	WebKeyFileEnv  = "WEB_KEY_FILE"

	// WebLogInfoKey 接口日志附带请求信息, 上下文键名
	WebLogInfoKey = "_WLIK_"

	// WebLogSlowResponse 慢日志条件
	WebLogSlowResponse = 5 * time.Second

	// WebLogMinStatusCode Web 日志响应码条件值
	WebLogMinStatusCode = 500

	// WebTimeout Web 请求超时
	WebTimeout = 30 * time.Second
)
View Source
var (
	// DefaultTimeZone 缺省时区名称
	DefaultTimeZone string

	// DefaultTimeLocation 默认时区
	// 优先尝试解析中国时区 (GMT+8), 失败(Windows)后使用本地时区
	DefaultTimeLocation *time.Location
)
View Source
var (
	Version   = "v0.0.1"
	GoVersion = ""
	GitCommit = ""

	// DebVersion 当前的包版本信息
	DebVersion = ""
)
View Source
var (
	// DefaultGOMAXPROCS 缺省的并发配置, 最少 4
	DefaultGOMAXPROCS = utils.MaxInt(runtime.NumCPU(), 4)
)
View Source
var (
	ExtraEnvFiles []string
)
View Source
var (
	NodeInfoFile = ""
)

Functions

func GetDataSource

func GetDataSource(args any) error

GetDataSource 获取源数据配置 可在应用级重定义该函数, 覆盖 common.Funcs["GetDataSource"]

func GetDevName

func GetDevName(name string) string

GetDevName 去除服务名称后缀, 得到包名

func IsSkipRemoteConfig

func IsSkipRemoteConfig() bool

IsSkipRemoteConfig 是否只使用本地配置文件

func LoadConf

func LoadConf() error

LoadConf 加载配置

Types

type DataSourceArgs

type DataSourceArgs struct {
	Time time.Time
	Conf FilesConf
}

type FilesConf

type FilesConf struct {
	Path            string `json:"path"`
	Method          string `json:"method"`
	SecretName      string `json:"secret_name"`
	API             string `json:"api"`
	Interval        int    `json:"interval"`
	RandomWait      int    `json:"random_wait"`
	SecretValue     string `json:"-"`
	GetConfDuration time.Duration
}

type LogConf

type LogConf struct {
	NoColor              bool   `json:"no_color"`
	Level                int    `json:"level"`
	File                 string `json:"file"`
	Period               int    `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"`
	PeriodDur            time.Duration
	PostIntervalDuration time.Duration
	PostBatchBytes       int
}

type M added in v0.0.10

type M struct{}

func (*M) Runtime added in v0.0.10

func (m *M) Runtime() error

Runtime 重新加载配置时运行

func (*M) Start added in v0.0.10

func (m *M) Start() error

Start 程序启动时初始化

func (*M) Stop added in v0.0.10

func (m *M) Stop() error

Stop 程序退出时运行

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 接口配置

func Config

func Config() *MainConf

Config 获取全局配置

type NodeConf

type NodeConf struct {
	NodeInfoFile string `json:"node_info_file"`
	IPAPI        string `json:"ip_api"`
	NodeInfo     NodeInfo
}

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 SYSConf

type SYSConf struct {
	RestartMain             bool     `json:"restart_main"`
	TimeSyncType            string   `json:"time_sync_type"`
	WatcherInterval         int      `json:"watcher_interval"`
	ReqTimeout              int      `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"`

	CertFile string `json:"-"`
	KeyFile  string `json:"-"`
}

Jump to

Keyboard shortcuts

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