107 lines
2.2 KiB
Go
107 lines
2.2 KiB
Go
package config
|
|
|
|
import (
|
|
"flag"
|
|
"github.com/BurntSushi/toml"
|
|
"github.com/uber/jaeger-client-go"
|
|
traceConfig "github.com/uber/jaeger-client-go/config"
|
|
xtime "gitlab.33.cn/chat/dtalk/pkg/time"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
confPath string
|
|
|
|
Conf *Config
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(&confPath, "conf", "gateway.toml", "default config path.")
|
|
}
|
|
|
|
// Init init config.
|
|
func Init() (err error) {
|
|
Conf = Default()
|
|
_, err = toml.DecodeFile(confPath, &Conf)
|
|
return
|
|
}
|
|
|
|
func Default() *Config {
|
|
return &Config{
|
|
Env: "debug",
|
|
Server: &HttpServer{
|
|
Addr: "0.0.0.0:18002",
|
|
},
|
|
Trace: traceConfig.Configuration{
|
|
ServiceName: "gateway",
|
|
Gen128Bit: true,
|
|
Sampler: &traceConfig.SamplerConfig{
|
|
Type: jaeger.SamplerTypeConst,
|
|
Param: 1,
|
|
},
|
|
Reporter: &traceConfig.ReporterConfig{
|
|
LogSpans: true,
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
|
},
|
|
},
|
|
Revoke: &Revoke{
|
|
Expire: xtime.Duration(time.Hour * 24),
|
|
},
|
|
AnswerRPCClient: &RPCClient{
|
|
RegAddrs: "127.0.0.1:2379",
|
|
Schema: "dtalk",
|
|
SrvName: "answer",
|
|
Dial: xtime.Duration(time.Second),
|
|
Timeout: xtime.Duration(time.Second),
|
|
},
|
|
StoreRPCClient: &RPCClient{
|
|
RegAddrs: "127.0.0.1:2379",
|
|
Schema: "dtalk",
|
|
SrvName: "store",
|
|
Dial: xtime.Duration(time.Second),
|
|
Timeout: xtime.Duration(time.Second),
|
|
},
|
|
GroupRPCClient: &RPCClient{
|
|
RegAddrs: "127.0.0.1:2379",
|
|
Schema: "dtalk",
|
|
SrvName: "group",
|
|
Dial: xtime.Duration(time.Second),
|
|
Timeout: xtime.Duration(time.Second),
|
|
},
|
|
}
|
|
}
|
|
|
|
type Config struct {
|
|
Env string
|
|
Server *HttpServer
|
|
Trace traceConfig.Configuration
|
|
Modules []Module
|
|
Revoke *Revoke
|
|
AnswerRPCClient *RPCClient
|
|
StoreRPCClient *RPCClient
|
|
GroupRPCClient *RPCClient
|
|
}
|
|
|
|
type HttpServer struct {
|
|
Addr string
|
|
}
|
|
|
|
// RPCClient is RPC client config.
|
|
type RPCClient struct {
|
|
RegAddrs string // etcd addrs, seperate by ','
|
|
Schema string
|
|
SrvName string // call
|
|
Dial xtime.Duration
|
|
Timeout xtime.Duration
|
|
}
|
|
|
|
type Module struct {
|
|
Name string `json:"name"` // enums: wallet、oa、redpacket
|
|
IsEnabled bool `json:"isEnabled"`
|
|
EndPoints []string `json:"endPoints"`
|
|
}
|
|
|
|
type Revoke struct {
|
|
Expire xtime.Duration
|
|
}
|