first commit
This commit is contained in:
67
service/generator/config/config.go
Normal file
67
service/generator/config/config.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/net/grpc"
|
||||
xgrpc "gitlab.33.cn/chat/dtalk/pkg/net/grpc"
|
||||
xtime "gitlab.33.cn/chat/dtalk/pkg/time"
|
||||
)
|
||||
|
||||
var (
|
||||
confPath string
|
||||
regAddrs string
|
||||
|
||||
// Conf config
|
||||
Conf *Config
|
||||
)
|
||||
|
||||
func init() {
|
||||
var (
|
||||
defAddrs = os.Getenv("REGADDRS")
|
||||
)
|
||||
flag.StringVar(&confPath, "conf", "generator.toml", "default config path.")
|
||||
flag.StringVar(®Addrs, "reg", defAddrs, "etcd register addrs. eg:127.0.0.1:2379")
|
||||
}
|
||||
|
||||
// Init init config.
|
||||
func Init() (err error) {
|
||||
Conf = Default()
|
||||
_, err = toml.DecodeFile(confPath, &Conf)
|
||||
return
|
||||
}
|
||||
|
||||
// Default new a config with specified defualt value.
|
||||
func Default() *Config {
|
||||
return &Config{
|
||||
Node: 1,
|
||||
GRPCServer: &xgrpc.ServerConfig{
|
||||
Network: "tcp",
|
||||
Addr: ":30002",
|
||||
Timeout: xtime.Duration(time.Second),
|
||||
KeepAliveMaxConnectionIdle: xtime.Duration(time.Second * 60),
|
||||
KeepAliveMaxConnectionAge: xtime.Duration(time.Hour * 2),
|
||||
KeepAliveMaxMaxConnectionAgeGrace: xtime.Duration(time.Second * 20),
|
||||
KeepAliveTime: xtime.Duration(time.Second * 60),
|
||||
KeepAliveTimeout: xtime.Duration(time.Second * 20),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Node int64
|
||||
//reg
|
||||
Reg *Reg
|
||||
//gRPC server
|
||||
GRPCServer *grpc.ServerConfig
|
||||
}
|
||||
|
||||
// Reg is service register/discovery config
|
||||
type Reg struct {
|
||||
Schema string
|
||||
SrvName string
|
||||
RegAddrs string // etcd addrs, seperate by ','
|
||||
}
|
||||
Reference in New Issue
Block a user