forked from zlyuancn/zapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
180 lines (159 loc) · 5.9 KB
/
config.go
File metadata and controls
180 lines (159 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
-------------------------------------------------
Author : zlyuancn
date: 2020/7/2
Description :
-------------------------------------------------
*/
package core
import (
"github.com/spf13/viper"
"github.com/zlyuancn/zlog"
)
// 配置结构
type Config struct {
// 框架配置
Frame FrameConfig
// 服务配置
Services ServicesConfig
// 组件配置
Components ComponentsConfig
}
// 配置
type IConfig interface {
// 获取配置
Config() *Config
// 解析数据到结构中
Parse(outPtr interface{}) error
// 解析指定分片的数据到结构中
ParseShard(shard string, outPtr interface{}) error
// 获取配置viper结构
GetViper() *viper.Viper
// 获取标记列表
Tags() []string
// 检查是否存在某个标记, 标记是忽略大小写的
HasTag(tag string) (ok bool)
}
// frame配置
type FrameConfig struct {
// debug标志
Debug bool
// 主动清理内存间隔时间(毫秒), <= 0 表示禁用
FreeMemoryInterval int
// 等待服务启动阶段1, 等待时间(毫秒), 如果时间到则临时认为服务启动成功并提前返回
WaitServiceRunTime int
// 等待服务启动阶段2, 等待服务启动阶段1时间到后继续等待服务启动, 等待时间(毫秒), 如果时间到则真正认为服务启动成功
ContinueWaitServiceRunTime int
// 标记列表, 注意: tag是忽略大小写的
Tags []string
// log配置
Log LogConfig
}
type LogConfig = zlog.LogConfig
// 服务配置
type ServicesConfig struct {
Api ApiServiceConfig
Grpc GrpcServiceConfig
Cron CronServiceConfig
MysqlBinlog MysqlBinlogServiceConfig
}
// api服务配置
type ApiServiceConfig struct {
Bind string // bind地址
IPWithNginxForwarded bool // 适配nginx的Forwarded获取ip, 优先级高于nginx的Real
IPWithNginxReal bool // 适配nginx的Real获取ip, 优先级高于sock连接的ip
LogResultInDevelop bool // 在开发环境记录api输出结果
ShowDetailedErrorInProduction bool // 在生产环境显示详细的错误
}
// grpc服务配置
type GrpcServiceConfig struct {
Bind string // bind地址
HeartbeatTime int // 心跳时间(毫秒),
}
// CronService配置
type CronServiceConfig struct {
ThreadCount int // 线程数
JobQueueSize int // job队列大小
}
// MysqlBinlogService配置
type MysqlBinlogServiceConfig struct {
Host string // mysql 主机地址
UserName string // 用户名, 最好是root
Password string // 密码
Charset *string // 字符集, 一般为utf8mb4
IncludeTableRegex []string // 包含的表正则匹配, 匹配的数据为 dbName.tableName
ExcludeTableRegex []string // 排除的表正则匹配, 匹配的数据为 dbName.tableName
DiscardNoMetaRowEvent bool // 放弃没有表元数据的row事件
DumpExecutionPath string // mysqldump执行路径, 如果为空则忽略mysqldump只使用binlog, mysqldump执行路径一般为mysqldump
IgnoreWKBDataParseError bool // 忽略wkb数据解析错误, 一般为POINT, GEOMETRY类型
}
// 组件配置
type ComponentsConfig struct {
GrpcClient map[string]GrpcClientConfig
Xorm map[string]XormConfig
Redis map[string]RedisConfig
ES7 map[string]ES7Config
Cache map[string]CacheConfig
}
// grpc客户端配置
type GrpcClientConfig struct {
Address string // 链接地址
Registry string // 注册器, 默认为 local
Balance string // 负载均衡, 默认为 round_robin
DialTimeout int // 连接超时(毫秒), 0表示不限, 默认为 1000
}
// xorm配置
type XormConfig struct {
Driver string // 驱动
Source string // 连接源
MaxIdleConns int // 最大空闲连接数
MaxOpenConns int // 最大连接池个数
ConnMaxLifetime int // 最大续航时间(毫秒, 0表示无限
}
// redis配置
type RedisConfig struct {
Address string // 地址: host1:port1,host2:port2
Password string // 密码
DB int // db, 只有单点有效
IsCluster bool // 是否为集群
PoolSize int // 客户端池大小
ReadTimeout int64 // 超时(毫秒
WriteTimeout int64 // 超时(毫秒
DialTimeout int64 // 超时(毫秒
}
// es7配置
type ES7Config struct {
Address string // 地址: http://localhost1:9200,http://localhost2:9200
UserName string // 用户名
Password string // 密码
DialTimeout int64 // 连接超时(毫秒
Sniff bool // 开启嗅探器
Healthcheck *bool // 心跳检查(默认true
Retry int // 重试次数
RetryInterval int // 重试间隔(毫秒)
GZip bool // 启用gzip压缩
}
// 缓存配置
type CacheConfig struct {
CacheDB string // 缓存db; default, no, memory, redis
Codec string // 编解码器; default, byte, json, jsoniter, msgpack, proto_buffer
DirectReturnOnCacheFault bool // 在缓存故障时直接返回缓存错误
PanicOnLoaderExists bool // 注册加载器时如果加载器已存在会panic, 设为false会替换旧的加载器
SingleFlight string // 单跑; default, no, single
DefaultExpire int64 // 默认有效时间, 毫秒, <= 0 表示永久
DefaultExpireMax int64 // 默认最大有效时间, 毫秒, 如果 > 0 且 DefaultExpire > 0, 则默认有效时间在 [DefaultExpire, DefaultExpireMax-1] 区间随机
MemoryCacheDB struct {
CleanupInterval int64 // 清除过期key时间间隔(毫秒)
}
RedisCacheDB struct {
KeyPrefix string // key前缀
Address string // 地址: host1:port1,host2:port2
Password string // 密码
DB int // db, 只有单点有效
IsCluster bool // 是否为集群
PoolSize int // 客户端池大小
ReadTimeout int64 // 读取超时(毫秒
WriteTimeout int64 // 写入超时(毫秒
DialTimeout int64 // 连接超时(毫秒
}
}