Documentation
¶
Index ¶
- func SetupConfig(v any, path string) error
- func WatchConfig(ctx context.Context, bc *Bootstrap, callbacks ...ReloadCallback)
- func WriteConfig(v any, path string) error
- type Bootstrap
- type Data
- type Database
- type Duration
- type Log
- type ReloadCallback
- type Runtime
- type Server
- type ServerHTTP
- type ServerPPROF
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WatchConfig ¶ added in v1.7.2
func WatchConfig(ctx context.Context, bc *Bootstrap, callbacks ...ReloadCallback)
WatchConfig 轮询配置文件 mtime,检测到变更后防抖 500ms 再重读并执行回调。 回调全部成功后将 new 的值覆写到 old(指针不变,内容替换)。 ctx 取消时退出。
Types ¶
type Bootstrap ¶
func DefaultConfig ¶ added in v1.3.0
func DefaultConfig() Bootstrap
type Data ¶
type Data struct {
// Database 数据库
Database Database `comment:"数据库支持 sqlite 和 postgres 两种,使用 sqlite 时 dsn 应当填写文件存储路径"`
}
Data 结构体,包含 Database 和 Redis 两个字段
type Database ¶
type Database struct {
Dsn string // 数据源名称
MaxIdleConns int32 // 最大空闲连接数
MaxOpenConns int32 // 最大打开连接数
ConnMaxLifetime Duration // 连接最大生命周期
SlowThreshold Duration // 慢查询阈值
}
Database 结构体,包含 Dsn、MaxIdleConns、MaxOpenConns、ConnMaxLifetime 和 SlowThreshold 五个字段
type Log ¶
type Log struct {
Name string `comment:"日志文件名(选填)"`
Dir string `comment:"日志存储目录,不能使用特殊符号"`
Level string `comment:"记录级别 debug/info/warn/error"`
MaxAge int `comment:"保留日志多久,超过时间自动删除"`
RotationTime Duration `comment:"多久时间,分割一个新的日志文件"`
MaxSize int `comment:"多大文件,分割一个新的日志文件(MB)"`
Compress bool `comment:"是否压缩日志"`
MaxBackups int `comment:"保留的旧日志归档文件最大数量,超出的自动删除"`
}
Log 结构体,包含 Dir、Level、MaxAge、RotationTime 和 RotationSize 五个字段
type ReloadCallback ¶ added in v1.7.2
ReloadCallback 配置重载回调,old 为当前生效配置,new 为新读取配置。 回调内应自行比对差异并执行重载动作,返回 error 则跳过本次重载。
type Server ¶
type Server struct {
HTTP ServerHTTP `comment:"对外提供的服务,建议由 nginx 代理"` // HTTP服务器
}
type ServerHTTP ¶
type ServerHTTP struct {
Port int `comment:"http 端口"` // 服务器端口号
Timeout Duration `comment:"请求超时时间"` // 请求超时时间
JwtSecret string `comment:"jwt 秘钥,空串时,每次启动程序将随机赋值"` // JWT密钥
PProf ServerPPROF // Pprof配置
}
type ServerPPROF ¶
type ServerPPROF struct {
Enabled bool `comment:"是否启用 pprof, 建议设置为 true"` // 是否启用
AccessIps []string `comment:"访问白名单" json:"access_ips"` // 允许访问的IP地址列表
}
ServerPPROF 结构体,包含 Enabled 和 AccessIps 两个字段
Click to show internal directories.
Click to hide internal directories.