This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
packagetraffic
import(
"net"
"net/rpc"
"sync"
"github.com/mafanr/juz/misc"
"github.com/mafanr/g"
"go.uber.org/zap"
)
vartraffic*Traffic
typeTrafficstruct{
Strategies*sync.Map
}
func(t*Traffic)Start(){
// 初始化mysql连接
misc.InitMysql()
// 加载配置数据
t.Strategies=&sync.Map{}
t.loadData()
// 启动rpc服务
t.startRpcServer()
traffic=t
}
func(t*Traffic)Shutdown(){
g.Info("shutdown tfe..")
}
typeRateLimiterstruct{}
// 请不要修改该函数,用来测试rpc是否存活
func(rl*RateLimiter)Ping(reqint,reply*int)error{
*reply=1
returnnil
}
func(t*Traffic)startRpcServer(){
rl:=new(RateLimiter)
server:=rpc.NewServer()
err:=server.Register(rl)
iferr!=nil{
g.Fatal("register error",zap.Error(err))
}
g.Info("Listen tcp on port",zap.String("port",misc.Conf.Traffic.Port))