Skip to content

Commit

Permalink
effective go format (#338)
Browse files Browse the repository at this point in the history
* effective go format

* revert pkg to util

* update tars2go version

* fix tarscurrent import trace error

* 修改trace合并panic

* 恢复导出结构体名

* 修复trace生成代码

* 基础服务不生成trace支持代码

* remove disable check SA4004

* remove disable check S1021

* annotation formatting

* trace demo add go.sum

* 注释格式整理

* update tars version

* tarsgo 新建项目 makefile 优化
  • Loading branch information
lbbniu authored Mar 12, 2022
1 parent 3299ba4 commit c979ca2
Show file tree
Hide file tree
Showing 75 changed files with 6,013 additions and 5,695 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
# Exit with 1 when it find at least one finding.
fail_on_error: true
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1019,-S1021,-SA4001,-SA4004
staticcheck_flags: -checks=inherit,-SA1019,-SA4001
235 changes: 235 additions & 0 deletions _examples/trace/TarsTraceBackServer/go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions _examples/trace/TarsTraceBackServer/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ CONFIG := client
STRIP_FLAG:= N
J2GO_FLAG:=

libpath=${subst :, ,$(GOPATH)}
$(eval -include scripts/makefile.tars.gomod)
-include scripts/makefile.tars.gomod
235 changes: 235 additions & 0 deletions _examples/trace/TarsTraceFrontServer/go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions _examples/trace/TarsTraceFrontServer/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ CONFIG := client
STRIP_FLAG:= N
J2GO_FLAG:=

libpath=${subst :, ,$(GOPATH)}
$(eval -include scripts/makefile.tars.gomod)
-include scripts/makefile.tars.gomod
9 changes: 4 additions & 5 deletions tars/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type AdapterProxy struct {
lastCheckTime int64
lastKeepAliveTime int64

//count int
closed bool
}

Expand All @@ -52,7 +51,7 @@ func NewAdapterProxy(objName string, point *endpointf.EndpointF, comm *Communica
}
conf := &transport.TarsClientConf{
Proto: proto,
//NumConnect: netthread,
// NumConnect: netthread,
QueueLen: comm.Client.ClientQueueLen,
IdleTimeout: comm.Client.ClientIdleTimeout,
ReadTimeout: comm.Client.ClientReadTimeout,
Expand Down Expand Up @@ -83,7 +82,7 @@ func (c *AdapterProxy) Recv(pkg []byte) {
// TODO readCh has a certain probability to be closed after the load, and we need to recover
// Maybe there is a better way
if err := recover(); err != nil {
TLOG.Error("recv pkg painc:", err)
TLOG.Error("recv pkg panic:", err)
}
}()
packet, err := c.obj.proto.ResponseUnpack(pkg)
Expand All @@ -103,7 +102,7 @@ func (c *AdapterProxy) Recv(pkg []byte) {
ch := chIF.(chan *requestf.ResponsePacket)
select {
case ch <- packet:
//after conf.ReadTimeout, release this goroutine to make sure response package is received by Tars_Invoke().
// after conf.ReadTimeout, release this goroutine to make sure response package is received by Tars_Invoke().
case <-rtimer.After(c.conf.ReadTimeout):
TLOG.Errorf("response timeout, write channel error, now time :%v, RequestId:%v",
time.Now().UnixNano()/1e6, packet.IRequestId)
Expand Down Expand Up @@ -212,7 +211,7 @@ func (c *AdapterProxy) onPush(pkg *requestf.ResponsePacket) {
defer cancel()
oldClient.GraceClose(ctx) // grace shutdown
}
//TODO: support push msg
// TODO: support push msg
}

func (c *AdapterProxy) doKeepAlive() {
Expand Down
8 changes: 4 additions & 4 deletions tars/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type Admin struct {
}

var (
isShutdownbyadmin int32 = 0
isShutdownByAdmin int32 = 0
)

// Shutdown shutdown all servant by admin
// Shutdown all servant by admin
func (a *Admin) Shutdown() error {
atomic.StoreInt32(&isShutdownbyadmin, 1)
atomic.StoreInt32(&isShutdownByAdmin, 1)
go graceShutdown()
return nil
}
Expand All @@ -33,7 +33,7 @@ func (a *Admin) Shutdown() error {
func (a *Admin) Notify(command string) (string, error) {
cmd := strings.Split(command, " ")
// report command to notify
go ReportNotifyInfo(NOTIFY_NORMAL, "AdminServant::notify:"+command)
go ReportNotifyInfo(NotifyNormal, "AdminServant::notify:"+command)
switch cmd[0] {
case "tars.viewversion":
return GetServerConfig().Version, nil
Expand Down
64 changes: 31 additions & 33 deletions tars/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/TarsCloud/TarsGo/tars/util/tools"
)

//var listenFds []*os.File
var tarsConfig map[string]*transport.TarsServerConf
var goSvrs map[string]*transport.TarsServer
var httpSvrs map[string]*http.Server
Expand Down Expand Up @@ -93,8 +92,8 @@ func initConfig() {
return
}

//Config.go
//init server config
// Config.go
// init server config
if strings.EqualFold(c.GetString("/tars/application<enableset>"), "Y") {
svrCfg.Enableset = true
svrCfg.Setdivision = c.GetString("/tars/application<setdivision>")
Expand All @@ -105,9 +104,9 @@ func initConfig() {
svrCfg.Server = sMap["server"]
svrCfg.LocalIP = sMap["localip"]
svrCfg.Local = c.GetString("/tars/application/server<local>")
//svrCfg.Container = c.GetString("/tars/application<container>")
// svrCfg.Container = c.GetString("/tars/application<container>")

//init log
// init log
svrCfg.LogPath = sMap["logpath"]
svrCfg.LogSize = tools.ParseLogSizeMb(sMap["logsize"])
svrCfg.LogNum = tools.ParseLogNum(sMap["lognum"])
Expand All @@ -118,9 +117,9 @@ func initConfig() {
svrCfg.DataPath = sMap["datapath"]
svrCfg.Log = sMap["log"]

//add version info
svrCfg.Version = TarsVersion
//add adapters config
// add version info
svrCfg.Version = Version
// add adapters config
svrCfg.Adapters = make(map[string]adapterConfig)

cachePath := filepath.Join(svrCfg.DataPath, svrCfg.Server) + ".tarsdat"
Expand All @@ -138,8 +137,8 @@ func initConfig() {
TLOG.SetFileRoller(svrCfg.LogPath+"/"+svrCfg.App+"/"+svrCfg.Server, 10, 100)
}

//cache
appCache.TarsVersion = TarsVersion
// cache
appCache.TarsVersion = Version

// add timeout config
svrCfg.AcceptTimeout = tools.ParseTimeOut(c.GetIntWithDef("/tars/application/server<accepttimeout>", AcceptTimeout))
Expand Down Expand Up @@ -179,7 +178,7 @@ func initConfig() {
}
}

//init client config
// init client config
cMap := c.GetMap("/tars/application/client")
cltCfg.Locator = cMap["locator"]
cltCfg.Stat = cMap["stat"]
Expand Down Expand Up @@ -217,14 +216,14 @@ func initConfig() {
endString := c.GetString("/tars/application/server/" + adapter + "<endpoint>")
end := endpoint.Parse(endString)
svrObj := c.GetString("/tars/application/server/" + adapter + "<servant>")
protocol := c.GetString("/tars/application/server/" + adapter + "<protocol>")
proto := c.GetString("/tars/application/server/" + adapter + "<protocol>")
threads := c.GetInt("/tars/application/server/" + adapter + "<threads>")
svrCfg.Adapters[adapter] = adapterConfig{end, protocol, svrObj, threads}
svrCfg.Adapters[adapter] = adapterConfig{end, proto, svrObj, threads}
host := end.Host
if end.Bind != "" {
host = end.Bind
}
conf := &transport.TarsServerConf{
svrConf := &transport.TarsServerConf{
Proto: end.Proto,
Address: fmt.Sprintf("%s:%d", host, end.Port),
MaxInvoke: svrCfg.MaxInvoke,
Expand All @@ -246,23 +245,23 @@ func initConfig() {
key := c.GetString("/tars/application/server/" + adapter + "<key>")
verifyClient := c.GetString("/tars/application/server/"+adapter+"<verifyclient>") != "0"
ciphers := c.GetString("/tars/application/server/" + adapter + "<ciphers>")
conf.TlsConfig, err = ssl.NewServerTlsConfig(ca, cert, key, verifyClient, ciphers)
svrConf.TlsConfig, err = ssl.NewServerTlsConfig(ca, cert, key, verifyClient, ciphers)
if err != nil {
panic(err)
}
} else {
conf.TlsConfig = tlsConfig
svrConf.TlsConfig = tlsConfig
}
}
tarsConfig[svrObj] = conf
tarsConfig[svrObj] = svrConf
}
TLOG.Debug("config add ", tarsConfig)

if len(svrCfg.Local) > 0 {
localpoint := endpoint.Parse(svrCfg.Local)
localPoint := endpoint.Parse(svrCfg.Local)
adminCfg := &transport.TarsServerConf{
Proto: "tcp",
Address: fmt.Sprintf("%s:%d", localpoint.Host, localpoint.Port),
Address: fmt.Sprintf("%s:%d", localPoint.Host, localPoint.Port),
MaxInvoke: svrCfg.MaxInvoke,
AcceptTimeout: svrCfg.AcceptTimeout,
ReadTimeout: svrCfg.ReadTimeout,
Expand All @@ -276,15 +275,15 @@ func initConfig() {
}

tarsConfig["AdminObj"] = adminCfg
svrCfg.Adapters["AdminAdapter"] = adapterConfig{localpoint, "tcp", "AdminObj", 1}
svrCfg.Adapters["AdminAdapter"] = adapterConfig{localPoint, "tcp", "AdminObj", 1}
RegisterAdmin(rogger.Admin, rogger.HandleDyeingAdmin)
}

auths := c.GetDomain("/tars/application/client")
for _, objName := range auths {
authInfo := make(map[string]string)
//authInfo["accesskey"] = c.GetString("/tars/application/client/" + objName + "<accesskey>")
//authInfo["secretkey"] = c.GetString("/tars/application/client/" + objName + "<secretkey>")
// authInfo["accesskey"] = c.GetString("/tars/application/client/" + objName + "<accesskey>")
// authInfo["secretkey"] = c.GetString("/tars/application/client/" + objName + "<secretkey>")
authInfo["ca"] = c.GetString("/tars/application/client/" + objName + "<ca>")
authInfo["cert"] = c.GetString("/tars/application/client/" + objName + "<cert>")
authInfo["key"] = c.GetString("/tars/application/client/" + objName + "<key>")
Expand Down Expand Up @@ -379,7 +378,7 @@ func Run() {
}
}(obj)
}
go ReportNotifyInfo(NOTIFY_NORMAL, "restart")
go ReportNotifyInfo(NotifyNormal, "restart")

lisDone.Wait()
if os.Getenv("GRACE_RESTART") == "1" {
Expand All @@ -389,7 +388,7 @@ func Run() {
grace.SignalUSR2(ppid)
}
}
mainloop()
mainLoop()
}

func graceRestart() {
Expand Down Expand Up @@ -419,10 +418,10 @@ func graceRestart() {
logfile = os.Stdout
}
files := []*os.File{os.Stdin, logfile, logfile}
for key, file := range grace.GetAllLisenFiles() {
for key, file := range grace.GetAllListenFiles() {
fd := fmt.Sprint(file.Fd())
newFd := len(files)
TLOG.Debugf("tranlate %s=%s to %s=%d", key, fd, key, newFd)
TLOG.Debugf("translate %s=%s to %s=%d", key, fd, key, newFd)
newEnvs = append(newEnvs, fmt.Sprintf("%s=%d", key, newFd))
files = append(files, file)
}
Expand All @@ -438,7 +437,7 @@ func graceRestart() {
Files: files,
})
if err != nil {
TLOG.Errorf("start supprocess failed %v", err)
TLOG.Errorf("start subprocess failed %v", err)
return
}
TLOG.Infof("subprocess start %d", process.Pid)
Expand All @@ -452,7 +451,7 @@ func graceShutdown() {
pid := os.Getpid()

var graceShutdownTimeout time.Duration
if atomic.LoadInt32(&isShutdownbyadmin) == 1 {
if atomic.LoadInt32(&isShutdownByAdmin) == 1 {
// shutdown by admin,we should need shorten the timeout
graceShutdownTimeout = tools.ParseTimeOut(GracedownTimeout)
} else {
Expand Down Expand Up @@ -517,7 +516,7 @@ func graceShutdown() {
func teerDown(err error) {
shutdownOnce.Do(func() {
if err != nil {
ReportNotifyInfo(NOTIFY_NORMAL, "server is fatal: "+err.Error())
ReportNotifyInfo(NotifyNormal, "server is fatal: "+err.Error())
fmt.Println(err)
TLOG.Error(err)
}
Expand All @@ -530,7 +529,7 @@ func handleSignal() {
grace.GraceHandler(usrFun, killFunc)
}

func mainloop() {
func mainLoop() {
ha := new(NodeFHelper)
comm := NewCommunicator()
node := GetServerConfig().Node
Expand All @@ -547,15 +546,15 @@ func mainloop() {
for {
select {
case <-shutdown:
ReportNotifyInfo(NOTIFY_NORMAL, "stop")
ReportNotifyInfo(NotifyNormal, "stop")
return
case <-loop.C:
if atomic.LoadInt32(&isShudowning) == 1 {
continue
}
for name, adapter := range svrCfg.Adapters {
if adapter.Protocol == "not_tars" {
//TODO not_tars support
// TODO not_tars support
ha.KeepAlive(name)
continue
}
Expand All @@ -565,7 +564,6 @@ func mainloop() {
}
}
}

}
}
}
14 changes: 7 additions & 7 deletions tars/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tars

import (
"github.com/TarsCloud/TarsGo/tars/util/tools"
"time"

"github.com/TarsCloud/TarsGo/tars/util/endpoint"
"github.com/TarsCloud/TarsGo/tars/util/tools"
)

var svrCfg *serverConfig
Expand Down Expand Up @@ -51,21 +51,21 @@ type serverConfig struct {
Isdocker bool
Enableset bool
Setdivision string
//add server timeout
// add server timeout
AcceptTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
HandleTimeout time.Duration
IdleTimeout time.Duration
ZombieTimeout time.Duration
QueueCap int
//add tcp config
// add tcp config
TCPReadBuffer int
TCPWriteBuffer int
TCPNoDelay bool
//add routine number
// add routine number
MaxInvoke int32
//add adapter & report config
// add adapter & report config
PropertyReportInterval time.Duration
StatReportInterval time.Duration
MainLoopTicker time.Duration
Expand All @@ -91,7 +91,7 @@ type clientConfig struct {
CheckStatusInterval int
KeepAliveInterval int
AsyncInvokeTimeout int
//add client timeout
// add client timeout
ClientQueueLen int
ClientIdleTimeout time.Duration
ClientReadTimeout time.Duration
Expand All @@ -112,7 +112,7 @@ func newServerConfig() *serverConfig {
LogSize: defaultRotateSizeMB,
LogNum: defaultRotateN,
LogLevel: "INFO",
Version: TarsVersion,
Version: Version,
LocalIP: tools.GetLocalIP(),
Local: "",
BasePath: "",
Expand Down
Loading

0 comments on commit c979ca2

Please sign in to comment.