Create & Init Project...
This commit is contained in:
38
app/admin/main/spy/conf/BUILD
Normal file
38
app/admin/main/spy/conf/BUILD
Normal file
@ -0,0 +1,38 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["conf.go"],
|
||||
importpath = "go-common/app/admin/main/spy/conf",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/cache/memcache:go_default_library",
|
||||
"//library/conf:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/rpc:go_default_library",
|
||||
"//library/time: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"],
|
||||
)
|
132
app/admin/main/spy/conf/conf.go
Normal file
132
app/admin/main/spy/conf/conf.go
Normal file
@ -0,0 +1,132 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"go-common/library/cache/memcache"
|
||||
"go-common/library/conf"
|
||||
"go-common/library/database/sql"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/rpc"
|
||||
"go-common/library/time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var (
|
||||
// config
|
||||
confPath string
|
||||
client *conf.Client
|
||||
// Conf config
|
||||
Conf = &Config{}
|
||||
)
|
||||
|
||||
// Config def.
|
||||
type Config struct {
|
||||
// base
|
||||
// db
|
||||
DB *DB
|
||||
// spy rpc client
|
||||
SpyRPC *rpc.ClientConfig
|
||||
AccountRPC *rpc.ClientConfig
|
||||
// memcache
|
||||
Memcache *Memcache
|
||||
// log
|
||||
Log *log.Config
|
||||
// customized property
|
||||
Property *Property
|
||||
HTTPServer *bm.ServerConfig
|
||||
}
|
||||
|
||||
// DB config.
|
||||
type DB struct {
|
||||
Spy *sql.Config
|
||||
}
|
||||
|
||||
// Memcache config.
|
||||
type Memcache struct {
|
||||
User *memcache.Config
|
||||
UserExpire time.Duration
|
||||
}
|
||||
|
||||
// Property config for biz logic.
|
||||
type Property struct {
|
||||
TelValidateURL string
|
||||
BlockAccountURL string
|
||||
UserInfoShard int64
|
||||
HistoryShard int64
|
||||
LoadEventTick time.Duration
|
||||
Score *struct {
|
||||
BaseInit int8
|
||||
EventInit int8
|
||||
}
|
||||
Punishment *struct {
|
||||
ScoreThreshold int8
|
||||
Times int8
|
||||
}
|
||||
Event *struct {
|
||||
ServiceName string
|
||||
BindMailAndTelLowRisk string
|
||||
BindMailOnly string
|
||||
BindNothing string
|
||||
BindTelLowRiskOnly string
|
||||
BindTelMediumRisk string
|
||||
BindTelHighRisk string
|
||||
BindTelUnknownRisk string
|
||||
}
|
||||
// activity events
|
||||
ActivityEvents map[int32]struct{}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "conf", "", "default config path")
|
||||
}
|
||||
|
||||
// Init int config
|
||||
func Init() error {
|
||||
if confPath != "" {
|
||||
return local()
|
||||
}
|
||||
return remote()
|
||||
}
|
Reference in New Issue
Block a user