Create & Init Project...
This commit is contained in:
49
app/service/main/location/cmd/BUILD
Normal file
49
app/service/main/location/cmd/BUILD
Normal file
@ -0,0 +1,49 @@
|
||||
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 = [
|
||||
"convey-test.toml",
|
||||
"location-example.toml",
|
||||
],
|
||||
importpath = "go-common/app/service/main/location/cmd",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/service/main/location/conf:go_default_library",
|
||||
"//app/service/main/location/rpc/server:go_default_library",
|
||||
"//app/service/main/location/server/grpc:go_default_library",
|
||||
"//app/service/main/location/server/http:go_default_library",
|
||||
"//app/service/main/location/service:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/rpc/warden:go_default_library",
|
||||
"//library/net/rpc/warden/resolver/livezk:go_default_library",
|
||||
"//library/net/trace: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"],
|
||||
)
|
114
app/service/main/location/cmd/convey-test.toml
Normal file
114
app/service/main/location/cmd/convey-test.toml
Normal file
@ -0,0 +1,114 @@
|
||||
# This is a TOML document. Boom.
|
||||
|
||||
version = "2.1.0"
|
||||
user = "nobody"
|
||||
pid = "/tmp/location-service.pid"
|
||||
dir = "./"
|
||||
perf = "0.0.0.0:6290"
|
||||
checkFile = "/data/www/location.html"
|
||||
family = "location-service"
|
||||
filePath = "../cmd/source"
|
||||
fileName = "SinaIP.txt"
|
||||
|
||||
filterZone = ["共享地址","局域网","本机地址"]
|
||||
|
||||
[tracer]
|
||||
family = "location-service"
|
||||
proto = "unixgram"
|
||||
addr = "172.16.33.46:5140"
|
||||
|
||||
[log]
|
||||
dir = "/data/log/location-service/"
|
||||
|
||||
[db]
|
||||
[db.zlimit]
|
||||
name = "172.16.33.205:3308"
|
||||
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_oversea?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 5
|
||||
idle = 5
|
||||
idleTimeout ="4h"
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "1s"
|
||||
[db.zlimit.breaker]
|
||||
window ="3s"
|
||||
sleep ="100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[redis]
|
||||
[redis.zlimit]
|
||||
name = "location-service"
|
||||
proto = "tcp"
|
||||
#addr = "172.16.33.54:6379"
|
||||
addr = "172.18.33.61:6812"
|
||||
idle = 10
|
||||
active = 10
|
||||
dialTimeout = "1s"
|
||||
readTimeout = "1s"
|
||||
writeTimeout = "1s"
|
||||
idleTimeout = "10s"
|
||||
expire = "10s"
|
||||
|
||||
[identify]
|
||||
whiteAccessKey = ""
|
||||
whiteMid = 0
|
||||
[identify.app]
|
||||
key = "53e2fa226f5ad348"
|
||||
secret = "3cf6bd1b0ff671021da5f424fea4b04a"
|
||||
[identify.host]
|
||||
auth = "http://passport.bilibili.com"
|
||||
secret = "http://open.bilibili.com"
|
||||
[identify.httpClient]
|
||||
key = "53e2fa226f5ad348"
|
||||
secret = "3cf6bd1b0ff671021da5f424fea4b04a"
|
||||
dial = "30ms"
|
||||
timeout = "100ms"
|
||||
keepAlive = "60s"
|
||||
[identify.httpClient.breaker]
|
||||
window = "10s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[identify.httpClient.url]
|
||||
"http://passport.bilibili.co/intranet/auth/tokenInfo" = {timeout = "100ms"}
|
||||
"http://passport.bilibili.co/intranet/auth/cookieInfo" = {timeout = "100ms"}
|
||||
"http://open.bilibili.co/api/getsecret" = {timeout = "500ms"}
|
||||
|
||||
[multiHTTP]
|
||||
[multiHTTP.inner]
|
||||
addrs = ["0.0.0.0:6291"]
|
||||
[multiHTTP.local]
|
||||
addrs = ["0.0.0.0:6292"]
|
||||
|
||||
[rpcServer2]
|
||||
[[rpcServer2.servers]]
|
||||
proto = "tcp"
|
||||
addr = "0.0.0.0:6293"
|
||||
weight = 10
|
||||
[rpcServer2.zookeeper]
|
||||
root = "/microservice/location-service/"
|
||||
addrs = ["172.18.33.172:2181"]
|
||||
timeout = "30s"
|
||||
|
||||
[accountRPC]
|
||||
pullInterval = "10s"
|
||||
group ="groupapp"
|
||||
[accountRPC.client]
|
||||
token="123456"
|
||||
proto = "tcp"
|
||||
addr = "172.16.33.56:6079"
|
||||
timeout = "10s"
|
||||
timer = 1000
|
||||
[accountRPC.client.breaker]
|
||||
window ="10s"
|
||||
sleep ="10ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[accountRPC.zookeeper]
|
||||
root = "/microservice/account-service/"
|
||||
addrs = ["172.18.33.172:2181"]
|
||||
timeout = "30s"
|
87
app/service/main/location/cmd/location-example.toml
Normal file
87
app/service/main/location/cmd/location-example.toml
Normal file
@ -0,0 +1,87 @@
|
||||
filePath = "./source"
|
||||
ipv4Name = "mydata4vipday4.ipdb"
|
||||
ipv6Name = "mydata6vipday4.ipdb"
|
||||
anonymFileName = "GeoIP2-Anonymous-IP.mmdb"
|
||||
anonymKey = "cOp1pc4JZRpf"
|
||||
filterZone = ["共享地址","局域网","本机地址"]
|
||||
|
||||
[host]
|
||||
maxmind = "https://download.maxmind.com"
|
||||
bvcip = "http://bvc-nerve.bilibili.co"
|
||||
|
||||
[log]
|
||||
dir = "/data/log/location-service/"
|
||||
|
||||
[db]
|
||||
[db.zlimit]
|
||||
name = "127.0.0.1:3306"
|
||||
dsn = "root:test@tcp(127.0.0.1:3306)/bilibili_oversea?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
|
||||
active = 5
|
||||
idle = 5
|
||||
idleTimeout ="4h"
|
||||
queryTimeout = "1s"
|
||||
execTimeout = "1s"
|
||||
tranTimeout = "1s"
|
||||
[db.zlimit.breaker]
|
||||
window ="3s"
|
||||
sleep ="100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
|
||||
[redis]
|
||||
[redis.zlimit]
|
||||
name = "location-service"
|
||||
proto = "tcp"
|
||||
addr = "172.18.33.61:6812"
|
||||
#addr = "172.16.33.54:6379"
|
||||
idle = 10
|
||||
active = 10
|
||||
dialTimeout = "1s"
|
||||
readTimeout = "1s"
|
||||
writeTimeout = "1s"
|
||||
idleTimeout = "10s"
|
||||
expire = "10s"
|
||||
|
||||
[bm]
|
||||
[bm.inner]
|
||||
addr = "0.0.0.0:6291"
|
||||
timeout = "1s"
|
||||
[bm.local]
|
||||
addr = "0.0.0.0:6292"
|
||||
timeout = "1s"
|
||||
|
||||
[rpcServer2]
|
||||
[[rpcServer2.servers]]
|
||||
proto = "tcp"
|
||||
addr = "0.0.0.0:6293"
|
||||
weight = 10
|
||||
[rpcServer2.zookeeper]
|
||||
root = "/microservice/location-service/"
|
||||
addrs = ["172.18.33.172:2181"]
|
||||
timeout = "30s"
|
||||
|
||||
[wardenServer]
|
||||
addr = "0.0.0.0:9000"
|
||||
timeout = "1s"
|
||||
|
||||
[liveZK]
|
||||
addrs = ["172.22.33.130:2181"]
|
||||
timeout = "30s"
|
||||
|
||||
[httpClient]
|
||||
key = "e7482d29be4a95b8"
|
||||
secret = "9e803791cdef756e75faee68e12b7442"
|
||||
dial = "80ms"
|
||||
timeout = "100ms"
|
||||
keepAlive = "60s"
|
||||
[httpClient.breaker]
|
||||
window = "1s"
|
||||
sleep = "100ms"
|
||||
bucket = 10
|
||||
ratio = 0.5
|
||||
request = 100
|
||||
[httpClient.Host]
|
||||
"api.live.bilibili.co" = {timeout = "200ms"}
|
||||
[httpClient.url]
|
||||
"http://api.bilibili.co/x/internal/v2/fav/video" = {timeout = "500ms"}
|
76
app/service/main/location/cmd/main.go
Normal file
76
app/service/main/location/cmd/main.go
Normal file
@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"go-common/app/service/main/location/conf"
|
||||
rpc "go-common/app/service/main/location/rpc/server"
|
||||
"go-common/app/service/main/location/server/grpc"
|
||||
"go-common/app/service/main/location/server/http"
|
||||
"go-common/app/service/main/location/service"
|
||||
"go-common/library/log"
|
||||
"go-common/library/net/rpc/warden"
|
||||
"go-common/library/net/rpc/warden/resolver/livezk"
|
||||
"go-common/library/net/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
discoveryID = "location.service"
|
||||
)
|
||||
|
||||
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)
|
||||
trace.Init(conf.Conf.Tracer)
|
||||
defer trace.Close()
|
||||
defer log.Close()
|
||||
// service init
|
||||
svr := service.New(conf.Conf)
|
||||
rpcSvr := rpc.New(conf.Conf, svr)
|
||||
// warden init
|
||||
var err error
|
||||
var cancelzk context.CancelFunc = func() {}
|
||||
var grpcSvr *warden.Server
|
||||
if conf.Conf.WardenServer != nil {
|
||||
grpcSvr = grpc.New(conf.Conf.WardenServer, svr)
|
||||
if conf.Conf.LiveZK != nil {
|
||||
if cancelzk, err = livezk.Register(conf.Conf.LiveZK, conf.Conf.WardenServer.Addr, discoveryID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// http init
|
||||
http.Init(conf.Conf, svr, rpcSvr)
|
||||
log.Info("location-service start")
|
||||
// init signal
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for s := range c {
|
||||
log.Info("location-service get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
cancelzk()
|
||||
if grpcSvr != nil {
|
||||
grpcSvr.Shutdown(context.Background())
|
||||
}
|
||||
rpcSvr.Close()
|
||||
time.Sleep(2 * time.Second)
|
||||
log.Info("location-service exit")
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
// TODO reload
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user