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,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["config-service-example.toml"],
importpath = "go-common/app/infra/config/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/infra/config/conf:go_default_library",
"//app/infra/config/http:go_default_library",
"//app/infra/config/rpc/server:go_default_library",
"//app/infra/config/service/v1:go_default_library",
"//app/infra/config/service/v2:go_default_library",
"//library/conf/env:go_default_library",
"//library/log:go_default_library",
"//library/naming:go_default_library",
"//library/naming/discovery:go_default_library",
"//library/net/ip: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,60 @@
# This is a TOML document. Boom.
pollTimeout = "30s"
pathCache = "/tmp/"
[log]
stdout = true
[antispam]
on=true
second=60
n=10
hour=12
m=500
[antispam.redis]
name = "config-service/hosts"
proto = "tcp"
addr = "172.18.33.61:6811"
idle = 100
active = 100
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "24h"
[ecode]
domain = "172.16.33.248:6401"
[db]
name = "[config]tcp@172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_apm?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 5
queryTimeout = "500ms"
execTimeout = "500ms"
tranTimeout = "500ms"
[db.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[redis]
name = "config-service/hosts"
proto = "tcp"
addr = "172.18.33.61:6811"
idle = 100
active = 100
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
[orm]
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_config?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 5
idleTimeout = "4h"

View File

@ -0,0 +1,82 @@
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"go-common/app/infra/config/conf"
"go-common/app/infra/config/http"
"go-common/app/infra/config/rpc/server"
"go-common/app/infra/config/service/v1"
"go-common/app/infra/config/service/v2"
"go-common/library/conf/env"
"go-common/library/log"
"go-common/library/naming"
"go-common/library/naming/discovery"
xip "go-common/library/net/ip"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
log.Error("conf.Init() error(%v)", err)
panic(err)
}
// init log
log.Init(conf.Conf.Log)
defer log.Close()
// service init
svr2 := v2.New(conf.Conf)
svr := v1.New(conf.Conf)
rpcSvr := rpc.New(conf.Conf, svr, svr2)
http.Init(conf.Conf, svr, svr2, rpcSvr)
// start discovery register
var (
err error
cancel context.CancelFunc
)
if env.IP == "" {
ip := xip.InternalIP()
hn, _ := os.Hostname()
dis := discovery.New(nil)
ins := &naming.Instance{
Zone: env.Zone,
Env: env.DeployEnv,
AppID: "config.service",
Hostname: hn,
Addrs: []string{
"http://" + ip + ":" + env.HTTPPort,
"gorpc://" + ip + ":" + env.GORPCPort,
},
}
if cancel, err = dis.Register(context.Background(), ins); err != nil {
panic(err)
}
}
// end discovery register
// init signal
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("config-service get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
if cancel != nil {
cancel()
}
rpcSvr.Close()
svr.Close()
log.Info("config-service exit")
return
case syscall.SIGHUP:
// TODO reload
default:
return
}
}
}