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,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"config.go",
"lancerroute.go",
],
importpath = "go-common/app/service/ops/log-agent/pkg/lancerroute",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/ops/log-agent/conf/configcenter:go_default_library",
"//library/log: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,60 @@
package lancerroute
import (
"time"
"fmt"
"go-common/app/service/ops/log-agent/conf/configcenter"
"go-common/library/log"
"github.com/BurntSushi/toml"
)
const (
lancerRouteFile = "lancerRoute.toml"
)
type Config struct {
LancerRoute map[string]string `toml:"lancerroute"`
}
func (l *Lancerroute) InitConfig() (err error) {
// read config from config center
if err = l.readConfig(); err != nil {
return err
}
// watch update and reload config
go func() {
currentVersion := configcenter.Version
for {
if currentVersion != configcenter.Version {
log.Info("lancer route config reload")
if err := l.readConfig(); err != nil {
log.Error("lancer route config reload error (%v", err)
}
currentVersion = configcenter.Version
}
time.Sleep(time.Second)
}
}()
return nil
}
func (l *Lancerroute) readConfig() (err error) {
var (
ok bool
value string
tmpLancerRoute Config
)
// sample config
if value, ok = configcenter.Client.Value(lancerRouteFile); !ok {
return fmt.Errorf("failed to get %s", lancerRouteFile)
}
if _, err = toml.Decode(value, &tmpLancerRoute); err != nil {
return err
}
l.c = &tmpLancerRoute
return nil
}

View File

@@ -0,0 +1,20 @@
package lancerroute
type Lancerroute struct {
c *Config
}
var route *Lancerroute
func InitLancerRoute() error {
route = new(Lancerroute)
return route.InitConfig()
}
func GetLancerByLogid(logId string) string {
if d, ok := route.c.LancerRoute[logId]; ok {
return d
}
// lancer-common by default
return "lancer-common"
}