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,34 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["config.go"],
importpath = "go-common/app/service/live/broadcast-proxy/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/conf:go_default_library",
"//library/log: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,106 @@
package conf
import (
"errors"
"github.com/BurntSushi/toml"
"go-common/library/conf"
"go-common/library/log"
xtime "go-common/library/time"
)
type BroadcastProxyConfig struct {
Perf string `toml:"perf"`
Log *log.Config
Http *HttpConfig
Backend *BackendConfig
ZooKeeper *ZooKeeperConfig
Ipip *IpipConfig
Dispatch *DispatchConfig
Sven *SvenConfig
}
type HttpConfig struct {
Address string
}
type BackendConfig struct {
MaxIdleConnsPerHost int
ProbePath string
BackendServer []string
ProbeSample int
}
type ZooKeeperConfig struct {
Address []string
Timeout xtime.Duration
ConfigPath string
}
type SinaIPConfig struct {
Data string
}
type IpipConfig struct {
V4 string
V6 string
}
type DispatchConfig struct {
MaxLimit int
DefaultDomain string
WildcardDomainSuffix string
FileName string
}
type SvenConfig struct {
TreeID string
Zone string
Env string
Build string
Token string
}
func NewBroadcastProxyConfig(file string) (*BroadcastProxyConfig, error) {
config := new(BroadcastProxyConfig)
if file != "" {
if err := config.local(file); err != nil {
return nil, err
}
} else {
if err := config.remote(); err != nil {
return nil, err
}
}
return config, nil
}
func (config *BroadcastProxyConfig) local(filename string) (err error) {
_, err = toml.DecodeFile(filename, config)
return
}
func (config *BroadcastProxyConfig) remote() error {
client, err := conf.New()
if err != nil {
return err
}
if err = config.load(client); err != nil {
return err
}
go func() {
for range client.Event() {
log.Info("config event")
}
}()
return nil
}
func (config *BroadcastProxyConfig) load(c *conf.Client) error {
s, ok := c.Value("live-broadcast-proxy.toml")
if !ok {
return errors.New("load config center error")
}
if _, err := toml.Decode(s, config); err != nil {
return errors.New("could not decode config")
}
return nil
}