forked from dotbitHQ/das-account-indexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
80 lines (74 loc) · 3 KB
/
config.go
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
package config
import (
"fmt"
"github.com/DeAccountSystems/das-lib/common"
"github.com/fsnotify/fsnotify"
"github.com/scorpiotzh/mylog"
"github.com/scorpiotzh/toolib"
)
var (
Cfg CfgServer
log = mylog.NewLogger("main", mylog.LevelDebug)
)
func InitCfg(configFilePath string) error {
if configFilePath == "" {
configFilePath = "./conf/config.yaml"
}
log.Info("config file path:", configFilePath)
if err := toolib.UnmarshalYamlFile(configFilePath, &Cfg); err != nil {
return fmt.Errorf("UnmarshalYamlFile err:%s", err.Error())
}
log.Info("config file info:", toolib.JsonString(Cfg))
return nil
}
func AddCfgFileWatcher(configFilePath string) (*fsnotify.Watcher, error) {
if configFilePath == "" {
configFilePath = "./conf/config.yaml"
}
return toolib.AddFileWatcher(configFilePath, func() {
log.Info("config file path:", configFilePath)
if err := toolib.UnmarshalYamlFile(configFilePath, &Cfg); err != nil {
log.Error("UnmarshalYamlFile err:", err.Error())
}
log.Info("config file info:", toolib.JsonString(Cfg))
})
}
type CfgServer struct {
Server struct {
Net common.DasNetType `json:"net" yaml:"net"`
HttpServerAddr string `json:"http_server_addr" yaml:"http_server_addr"`
HttpServerAddrIndexer string `json:"http_server_addr_indexer" yaml:"http_server_addr_indexer"`
HttpServerAddrReverse string `json:"http_server_addr_reverse" yaml:"http_server_addr_reverse"`
} `json:"server" yaml:"server"`
Chain struct {
CkbUrl string `json:"ckb_url" yaml:"ckb_url"`
IndexUrl string `json:"index_url" yaml:"index_url"`
CurrentBlockNumber uint64 `json:"current_block_number" yaml:"current_block_number"`
ConfirmNum uint64 `json:"confirm_num" yaml:"confirm_num"`
ConcurrencyNum uint64 `json:"concurrency_num" yaml:"concurrency_num"`
} `json:"chain" yaml:"chain"`
DB struct {
Mysql DbMysql `json:"mysql" yaml:"mysql"`
} `json:"db" yaml:"db"`
Cache struct {
Redis struct {
Addr string `json:"addr" yaml:"addr"`
Password string `json:"password" yaml:"password"`
DbNum int `json:"db_num" yaml:"db_num"`
} `json:"redis" yaml:"redis"`
} `json:"cache" yaml:"cache"`
DasLib struct {
THQCodeHash string `json:"thq_code_hash" yaml:"thq_code_hash"`
DasContractArgs string `json:"das_contract_args" yaml:"das_contract_args"`
DasContractCodeHash string `json:"das_contract_code_hash" yaml:"das_contract_code_hash"`
MapDasContract map[common.DasContractName]string `json:"map_das_contract" yaml:"map_das_contract"`
} `json:"das_lib" yaml:"das_lib"`
}
type DbMysql struct {
Addr string `json:"addr" yaml:"addr"`
User string `json:"user" yaml:"user"`
Password string `json:"password" yaml:"password"`
DbName string `json:"db_name" yaml:"db_name"`
MaxOpenConn int `json:"max_open_conn" yaml:"max_open_conn"`
MaxIdleConn int `json:"max_idle_conn" yaml:"max_idle_conn"`
}