Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
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/job/main/thumbup/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/tidb:go_default_library",
"//library/log:go_default_library",
"//library/queue/databus:go_default_library",
"//library/queue/databus/databusutil:go_default_library",
"//library/sync/pipeline: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"],
)

View File

@@ -0,0 +1,112 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/tidb"
"go-common/library/log"
"go-common/library/queue/databus"
"go-common/library/queue/databus/databusutil"
"go-common/library/sync/pipeline"
xtime "go-common/library/time"
"github.com/BurntSushi/toml"
)
var (
// Conf global variable.
Conf = &Config{}
client *conf.Client
confPath string
)
// Config .
type Config struct {
Redis *Redis
Tidb *tidb.Config
ItemTidb *tidb.Config
Log *log.Config
Databus *Databus
Thumbup *Thumbup
Memcache *Memcache
StatMerge *StatMerge
Merge *pipeline.Config
LikeDatabusutil *databusutil.Config
ItemLikesDatabusutil *databusutil.Config
UserLikesDatabusutil *databusutil.Config
}
// StatMerge .
type StatMerge struct {
Business string
Target int64
Sources []int64
}
// Redis .
type Redis struct {
*redis.Config
StatsExpire xtime.Duration
UserLikesExpire xtime.Duration
ItemLikesExpire xtime.Duration
}
// Memcache .
type Memcache struct {
*memcache.Config
StatsExpire xtime.Duration
}
// Databus .
type Databus struct {
Stat *databus.Config
Like *databus.Config
ItemLikes *databus.Config
UserLikes *databus.Config
}
// Thumbup .
type Thumbup struct {
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init create config instance.
func Init() (err 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
}
err = load()
return
}
func load() (err error) {
str, ok := client.Toml2()
if !ok {
return errors.New("load config center error")
}
var tmpConf *Config
if _, err = toml.Decode(str, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}