Create & Init Project...
This commit is contained in:
49
app/service/live/xuser/conf/BUILD
Normal file
49
app/service/live/xuser/conf/BUILD
Normal file
@ -0,0 +1,49 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"conf.go",
|
||||
"log_hash.go",
|
||||
"tool.go",
|
||||
],
|
||||
importpath = "go-common/app/service/live/xuser/conf",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/cache/redis:go_default_library",
|
||||
"//library/conf:go_default_library",
|
||||
"//library/database/orm:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/verify:go_default_library",
|
||||
"//library/net/rpc:go_default_library",
|
||||
"//library/net/rpc/liverpc:go_default_library",
|
||||
"//library/net/rpc/warden:go_default_library",
|
||||
"//library/net/trace:go_default_library",
|
||||
"//library/queue/databus:go_default_library",
|
||||
"//vendor/github.com/BurntSushi/toml:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
138
app/service/live/xuser/conf/conf.go
Normal file
138
app/service/live/xuser/conf/conf.go
Normal file
@ -0,0 +1,138 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"go-common/library/net/rpc/warden"
|
||||
|
||||
"go-common/library/queue/databus"
|
||||
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/cache/redis"
|
||||
"go-common/library/conf"
|
||||
"go-common/library/database/orm"
|
||||
"go-common/library/database/sql"
|
||||
eCode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/http/blademaster/middleware/verify"
|
||||
"go-common/library/net/rpc"
|
||||
liverRPC "go-common/library/net/rpc/liverpc"
|
||||
"go-common/library/net/trace"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var (
|
||||
confPath string
|
||||
// TraceInit weather need init trace
|
||||
TraceInit bool
|
||||
client *conf.Client
|
||||
// Conf config
|
||||
Conf = &Config{}
|
||||
)
|
||||
|
||||
// Config .
|
||||
type Config struct {
|
||||
Log *log.Config
|
||||
BM *bm.ServerConfig
|
||||
BMClient *bm.ClientConfig
|
||||
Verify *verify.Config
|
||||
Tracer *trace.Config
|
||||
VipRedis *redis.Config
|
||||
GuardRedis *redis.Config
|
||||
Redis *redis.Config
|
||||
Memcache *memcache.Config
|
||||
ExpMemcache *memcache.Config
|
||||
LiveUserMysql *sql.Config
|
||||
LiveAppMySQL *sql.Config
|
||||
LiveAppORM *orm.Config
|
||||
Ecode *eCode.Config
|
||||
LiveVipChangePub *databus.Config
|
||||
UserExpMySQL *sql.Config
|
||||
LiveRPC map[string]*liverRPC.ClientConfig
|
||||
LiveEntryEffectPub *databus.Config
|
||||
GuardCfg *GuardCfg
|
||||
AccountRPC *rpc.ClientConfig
|
||||
Switch *ConfigSwitch
|
||||
UserExpExpire *UserExpExpireConf
|
||||
UserDaHangHaiExpire *UserDhhExpireConf
|
||||
// report
|
||||
Report *databus.Config
|
||||
XanchorClient *warden.ClientConfig
|
||||
}
|
||||
|
||||
// GuardCfg config for guard
|
||||
type GuardCfg struct {
|
||||
OpenEntryEffectDatabus bool
|
||||
EnableGuardBroadcast bool
|
||||
DanmuHost string
|
||||
}
|
||||
|
||||
// ConfigSwitch config for query
|
||||
type ConfigSwitch struct {
|
||||
QueryExp int
|
||||
}
|
||||
|
||||
// UserExpExpireConf config for cache expire
|
||||
type UserExpExpireConf struct {
|
||||
ExpireTime int32
|
||||
}
|
||||
|
||||
// UserDhhExpireConf config for cache expire
|
||||
type UserDhhExpireConf struct {
|
||||
ExpireTime int32
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "conf", "", "default config path")
|
||||
flag.BoolVar(&TraceInit, "traceInit", true, "default trace init")
|
||||
}
|
||||
|
||||
// Init init conf
|
||||
func Init() error {
|
||||
if confPath != "" {
|
||||
return local()
|
||||
}
|
||||
return remote()
|
||||
}
|
||||
|
||||
func local() (err error) {
|
||||
_, err = toml.DecodeFile(confPath, &Conf)
|
||||
return
|
||||
}
|
||||
|
||||
func remote() (err error) {
|
||||
if client, err = conf.New(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = load(); err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
for range client.Event() {
|
||||
log.Info("config reload")
|
||||
if load() != nil {
|
||||
log.Error("config reload error (%v)", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func load() (err error) {
|
||||
var (
|
||||
s string
|
||||
ok bool
|
||||
tmpConf *Config
|
||||
)
|
||||
if s, ok = client.Toml2(); !ok {
|
||||
return errors.New("load config center error")
|
||||
}
|
||||
if _, err = toml.Decode(s, &tmpConf); err != nil {
|
||||
return errors.New("could not decode config")
|
||||
}
|
||||
*Conf = *tmpConf
|
||||
return
|
||||
}
|
19
app/service/live/xuser/conf/log_hash.go
Normal file
19
app/service/live/xuser/conf/log_hash.go
Normal file
@ -0,0 +1,19 @@
|
||||
package conf
|
||||
|
||||
const (
|
||||
// GetFromDHHDBError 回源db错误
|
||||
GetFromDHHDBError = "get_from_dhh_db"
|
||||
// ScanFromDHHDBError scan db错误
|
||||
ScanFromDHHDBError = "scan_db"
|
||||
// _INFO_ADD_ANCHOREXP_RETRY_UPDATEDB = "AI1"
|
||||
// _ERROR_ADD_USEREXP_UPDATEDB_RETRYALL_FAIL = "UE1"
|
||||
// _ERROR_QUERY_AFTER_ADD_USEREXP_UPDATEDB_FAIL = "UE2"
|
||||
// _ERROR_QUERY_AFTER_ADD_ANCHOREXP_UPDATEDB_FAIL = "AE1"
|
||||
// _INFO_ADD_USEREXP_RETRY_UPDATEDB = "UI1"
|
||||
// _ERROR_GETEXP_DB_FAIL = "GE1"
|
||||
// _ERROR_ASYNC_CACHE_FAIL = "SE1"
|
||||
// _ERROR_ASYNC_CACHE_FAIL2 = "SE2"
|
||||
// _ERROR_ADD_ANCHOREXP_UPDATEDB_RETRYALL_FAIL = "AE2"
|
||||
// _ERROR_ASYNC_CACHE_FAIL3 = "SE3"
|
||||
// _ERROR_QUERY_CACHE_FAIL = "CE1"
|
||||
)
|
17
app/service/live/xuser/conf/tool.go
Normal file
17
app/service/live/xuser/conf/tool.go
Normal file
@ -0,0 +1,17 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"go-common/library/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RecordTimeCostLog 记录日志
|
||||
func RecordTimeCostLog(nowTime int64, desc string) {
|
||||
log.Info(desc+"|%d", nowTime)
|
||||
}
|
||||
|
||||
// RecordTimeCost ...
|
||||
// 记录时间
|
||||
func RecordTimeCost() (NowTime int64) {
|
||||
return time.Now().UnixNano() / 1000000 // 用毫秒
|
||||
}
|
Reference in New Issue
Block a user