Skip to content

Commit

Permalink
golint most of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sandyskies committed Nov 14, 2018
1 parent a411a98 commit 20bd168
Show file tree
Hide file tree
Showing 33 changed files with 305 additions and 71 deletions.
11 changes: 5 additions & 6 deletions tars/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var httpSvrs map[string]*http.Server
var shutdown chan bool
var serList []string
var objRunList []string

//TLOG is the logger for tars framework.
var TLOG = rogger.GetLogger("TLOG")
var initOnce sync.Once

Expand All @@ -37,20 +39,16 @@ func init() {
httpSvrs = make(map[string]*http.Server)
shutdown = make(chan bool, 1)
adminMethods = make(map[string]adminFn)
//在配置初始化前将日志关闭,减少独立客户端日志
rogger.SetLevel(rogger.ERROR)
Init()
}

//有些场景下需要提前初始化时调用:
//比如Imp里调用了通信器、
//AddServant时使用了全局配置等等。
//Init should run before GetServerConfig & GetClientConfig , or before run
// and Init should be only run once
func Init() {
initOnce.Do(initConfig)
}

//服务的初始化函数,默认会在Run的时候启动
//
func initConfig() {
confPath := flag.String("config", "", "init config path")
flag.Parse()
Expand Down Expand Up @@ -158,6 +156,7 @@ func initConfig() {
go initProReport()
}

//Run the application
func Run() {
Init()
<-statInited
Expand Down
11 changes: 9 additions & 2 deletions tars/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package tars

import (
"fmt"
"github.com/TarsCloud/TarsGo/tars/protocol/res/statf"
"net/http"
"strings"
"time"

"github.com/TarsCloud/TarsGo/tars/protocol/res/statf"
)

var realIPHeader []string
Expand All @@ -14,10 +15,11 @@ func init() {
realIPHeader = []string{ // the order is important
"X-Real-Ip",
"X-Forwarded-For-Pound",
"X-Forwarded-For", //是一个列表,暂时全报吧
"X-Forwarded-For",
}
}

//TarsHttpConf is configuration for tars http server.
type TarsHttpConf struct {
Container string
AppName string
Expand All @@ -27,6 +29,7 @@ type TarsHttpConf struct {
SetId string
}

//TarsHttpMux is http.ServeMux for tars http server.
type TarsHttpMux struct {
http.ServeMux
cfg *TarsHttpConf
Expand All @@ -39,6 +42,7 @@ type httpStatInfo struct {
costTime int64
}

//ServeHTTP is the server for the TarsHttpMux.
func (mux *TarsHttpMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "*" {
if r.ProtoAtLeast(1, 1) {
Expand Down Expand Up @@ -114,15 +118,18 @@ func (mux *TarsHttpMux) reportHttpStat(st *httpStatInfo) {
StatReport.pushBackMsg(info, true)
}

//SetConfig sets the cfg tho the TarsHttpMux.
func (mux *TarsHttpMux) SetConfig(cfg *TarsHttpConf) {
mux.cfg = cfg
}

//TarsResponseWriter is http.ResponseWriter for tars.
type TarsResponseWriter struct {
http.ResponseWriter
statusCode int
}

//WriteHeader is used for write the http header with the http code.
func (w *TarsResponseWriter) WriteHeader(code int) {
w.statusCode = code
w.ResponseWriter.WriteHeader(code)
Expand Down
6 changes: 4 additions & 2 deletions tars/logger.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package tars

import (
"github.com/TarsCloud/TarsGo/tars/util/rogger"
"path/filepath"

"github.com/TarsCloud/TarsGo/tars/util/rogger"
)

// GetLogger Get a logger
Expand Down Expand Up @@ -42,14 +43,15 @@ func GetHourLogger(name string, numHour int) *rogger.Logger {
return lg
}

//GetRemoteLogger returns a remote logger
func GetRemoteLogger(name string) *rogger.Logger {
cfg := GetServerConfig()
lg := rogger.GetLogger(name)
if !lg.IsConsoleWriter() {
return lg
}
remoteWriter := NewRemoteTimeWriter()
var set string = ""
var set string
if cfg.Enableset {
set = cfg.Setdivision
}
Expand Down
2 changes: 1 addition & 1 deletion tars/model/Servant.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
)

//Servant is interface for call the remote server.
type Servant interface {
Tars_invoke(ctx context.Context, ctype byte,
sFuncName string,
Expand Down
7 changes: 6 additions & 1 deletion tars/nodef.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package tars

import (
"github.com/TarsCloud/TarsGo/tars/protocol/res/nodef"
"os"

"github.com/TarsCloud/TarsGo/tars/protocol/res/nodef"
)

//NodeFHelper is helper struct.
type NodeFHelper struct {
comm *Communicator
si nodef.ServerInfo
sf *nodef.ServerF
}

//SetNodeInfo sets the node location for the given Communicator.
func (n *NodeFHelper) SetNodeInfo(comm *Communicator, node string, app string, server string) {
n.comm = comm
n.sf = new(nodef.ServerF)
Expand All @@ -25,6 +28,7 @@ func (n *NodeFHelper) SetNodeInfo(comm *Communicator, node string, app string, s
}
}

//KeepAlive sends the keepalive pacakage to the node.
func (n *NodeFHelper) KeepAlive(adapter string) {
n.si.Adapter = adapter
_, err := n.sf.KeepAlive(&n.si)
Expand All @@ -33,6 +37,7 @@ func (n *NodeFHelper) KeepAlive(adapter string) {
}
}

//ReportVersion report the tars version to the node.
func (n *NodeFHelper) ReportVersion(version string) {
_, err := n.sf.ReportVersion(n.si.Application, n.si.ServerName, version)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tars/notifyf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package tars

import "github.com/TarsCloud/TarsGo/tars/protocol/res/notifyf"

//NotifyHelper is the helper struct for the Notify service.
type NotifyHelper struct {
comm *Communicator
tn *notifyf.Notify
tm notifyf.ReportInfo
}

//SetNotifyInfo sets the notify server location for the Communicator.
func (n *NotifyHelper) SetNotifyInfo(comm *Communicator, notify string, app string, server string, container string) {
n.comm = comm
n.comm.SetProperty("netthread", 1)
Expand All @@ -30,6 +32,7 @@ func (n *NotifyHelper) SetNotifyInfo(comm *Communicator, notify string, app stri
}
}

//ReportNotifyInfo report the info to the notify server.
func (n *NotifyHelper) ReportNotifyInfo(info string) {
n.tm.SMessage = info
TLOG.Debug(n.tm)
Expand Down
Loading

0 comments on commit 20bd168

Please sign in to comment.