From fa9356936b49f60eba62fa49b05869eddbf461b1 Mon Sep 17 00:00:00 2001 From: fatedier <512654112@qq.com> Date: Wed, 3 Feb 2016 18:46:24 +0800 Subject: [PATCH] Use go fmt before build --- Makefile | 5 ++++- cmd/frpc/config.go | 11 +++++------ cmd/frpc/control.go | 8 ++++---- cmd/frpc/main.go | 2 +- cmd/frps/config.go | 11 +++++------ cmd/frps/control.go | 14 +++++++------- cmd/frps/main.go | 2 +- pkg/models/client.go | 16 ++++++++-------- pkg/models/msg.go | 13 ++++++------- pkg/models/server.go | 28 ++++++++++++++-------------- pkg/utils/conn/conn.go | 20 ++++++++++---------- pkg/utils/log/log.go | 2 +- 12 files changed, 66 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index 682c9e4..0151542 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,15 @@ export PATH := $(GOPATH)/bin:$(PATH) all: build -build: godep frps frpc +build: godep fmt frps frpc godep: @go get github.com/tools/godep godep restore +fmt: + @godep go fmt ./... + frps: godep go build -o bin/frps ./cmd/frps diff --git a/cmd/frpc/config.go b/cmd/frpc/config.go index c543793..5374222 100644 --- a/cmd/frpc/config.go +++ b/cmd/frpc/config.go @@ -11,16 +11,15 @@ import ( // common config var ( - ServerAddr string = "0.0.0.0" - ServerPort int64 = 7000 - LogFile string = "./frpc.log" - LogLevel string = "warn" - LogWay string = "file" + ServerAddr string = "0.0.0.0" + ServerPort int64 = 7000 + LogFile string = "./frpc.log" + LogLevel string = "warn" + LogWay string = "file" ) var ProxyClients map[string]*models.ProxyClient = make(map[string]*models.ProxyClient) - func LoadConf(confFile string) (err error) { var tmpStr string var ok bool diff --git a/cmd/frpc/control.go b/cmd/frpc/control.go index 87621e6..313bfcb 100644 --- a/cmd/frpc/control.go +++ b/cmd/frpc/control.go @@ -1,9 +1,9 @@ package main import ( + "encoding/json" "io" "sync" - "encoding/json" "github.com/fatedier/frp/pkg/models" "github.com/fatedier/frp/pkg/utils/conn" @@ -22,9 +22,9 @@ func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) { defer c.Close() req := &models.ClientCtlReq{ - Type: models.ControlConn, - ProxyName: cli.Name, - Passwd: cli.Passwd, + Type: models.ControlConn, + ProxyName: cli.Name, + Passwd: cli.Passwd, } buf, _ := json.Marshal(req) err = c.Write(string(buf) + "\n") diff --git a/cmd/frpc/main.go b/cmd/frpc/main.go index df87873..1bb5eb3 100644 --- a/cmd/frpc/main.go +++ b/cmd/frpc/main.go @@ -3,7 +3,7 @@ package main import ( "os" "sync" - + "github.com/fatedier/frp/pkg/utils/log" ) diff --git a/cmd/frps/config.go b/cmd/frps/config.go index 275e9e9..b7564c2 100644 --- a/cmd/frps/config.go +++ b/cmd/frps/config.go @@ -11,16 +11,15 @@ import ( // common config var ( - BindAddr string = "0.0.0.0" - BindPort int64 = 9527 - LogFile string = "./frps.log" - LogLevel string = "warn" - LogWay string = "file" + BindAddr string = "0.0.0.0" + BindPort int64 = 9527 + LogFile string = "./frps.log" + LogLevel string = "warn" + LogWay string = "file" ) var ProxyServers map[string]*models.ProxyServer = make(map[string]*models.ProxyServer) - func LoadConf(confFile string) (err error) { var tmpStr string var ok bool diff --git a/cmd/frps/control.go b/cmd/frps/control.go index 18ddb0a..4e58738 100644 --- a/cmd/frps/control.go +++ b/cmd/frps/control.go @@ -1,12 +1,12 @@ package main import ( - "fmt" "encoding/json" + "fmt" - "github.com/fatedier/frp/pkg/utils/log" - "github.com/fatedier/frp/pkg/utils/conn" "github.com/fatedier/frp/pkg/models" + "github.com/fatedier/frp/pkg/utils/conn" + "github.com/fatedier/frp/pkg/utils/log" ) func ProcessControlConn(l *conn.Listener) { @@ -41,7 +41,7 @@ func controlWorker(c *conn.Conn) { clientCtlRes.Code = 1 clientCtlRes.Msg = msg } - + if needRes { buf, _ := json.Marshal(clientCtlRes) err = c.Write(string(buf) + "\n") @@ -49,7 +49,7 @@ func controlWorker(c *conn.Conn) { log.Warn("Write error, %v", err) } } else { - // work conn, just return + // work conn, just return return } @@ -96,7 +96,7 @@ func checkProxy(req *models.ClientCtlReq, c *conn.Conn) (succ bool, msg string, log.Warn(msg) return } - + // control conn if req.Type == models.ControlConn { if server.Status != models.Idle { @@ -115,7 +115,7 @@ func checkProxy(req *models.ClientCtlReq, c *conn.Conn) (succ bool, msg string, log.Info("ProxyName [%s], start proxy success", req.ProxyName) } else if req.Type == models.WorkConn { - // work conn + // work conn needRes = false if server.Status != models.Working { log.Warn("ProxyName [%s], is not working when it gets one new work conn", req.ProxyName) diff --git a/cmd/frps/main.go b/cmd/frps/main.go index 3970341..83fdc48 100644 --- a/cmd/frps/main.go +++ b/cmd/frps/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/fatedier/frp/pkg/utils/log" "github.com/fatedier/frp/pkg/utils/conn" + "github.com/fatedier/frp/pkg/utils/log" ) func main() { diff --git a/pkg/models/client.go b/pkg/models/client.go index 042e75b..38fa9be 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -8,9 +8,9 @@ import ( ) type ProxyClient struct { - Name string - Passwd string - LocalPort int64 + Name string + Passwd string + LocalPort int64 } func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) { @@ -24,7 +24,7 @@ func (p *ProxyClient) GetLocalConn() (c *conn.Conn, err error) { func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err error) { c = &conn.Conn{} - defer func(){ + defer func() { if err != nil { c.Close() } @@ -37,9 +37,9 @@ func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err } req := &ClientCtlReq{ - Type: WorkConn, - ProxyName: p.Name, - Passwd: p.Passwd, + Type: WorkConn, + ProxyName: p.Name, + Passwd: p.Passwd, } buf, _ := json.Marshal(req) @@ -64,7 +64,7 @@ func (p *ProxyClient) StartTunnel(serverAddr string, serverPort int64) (err erro } log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", localConn.GetLocalAddr(), localConn.GetRemoteAddr(), - remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr()) + remoteConn.GetLocalAddr(), remoteConn.GetRemoteAddr()) go conn.Join(localConn, remoteConn) return nil } diff --git a/pkg/models/msg.go b/pkg/models/msg.go index 0062556..a3018e7 100644 --- a/pkg/models/msg.go +++ b/pkg/models/msg.go @@ -1,8 +1,8 @@ package models type GeneralRes struct { - Code int64 `json:"code"` - Msg string `json:"msg"` + Code int64 `json:"code"` + Msg string `json:"msg"` } // type @@ -12,16 +12,15 @@ const ( ) type ClientCtlReq struct { - Type int64 `json:"type"` - ProxyName string `json:"proxy_name"` - Passwd string `json:"passwd"` + Type int64 `json:"type"` + ProxyName string `json:"proxy_name"` + Passwd string `json:"passwd"` } type ClientCtlRes struct { GeneralRes } - type ServerCtlReq struct { - Type int64 `json:"type"` + Type int64 `json:"type"` } diff --git a/pkg/models/server.go b/pkg/models/server.go index 172a290..b6bff36 100644 --- a/pkg/models/server.go +++ b/pkg/models/server.go @@ -1,8 +1,8 @@ package models import ( - "sync" "container/list" + "sync" "github.com/fatedier/frp/pkg/utils/conn" "github.com/fatedier/frp/pkg/utils/log" @@ -14,17 +14,17 @@ const ( ) type ProxyServer struct { - Name string - Passwd string - BindAddr string - ListenPort int64 + Name string + Passwd string + BindAddr string + ListenPort int64 - Status int64 - Listener *conn.Listener // accept new connection from remote users - CtlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel - CliConnChan chan *conn.Conn // get client conns from control goroutine - UserConnList *list.List // store user conns - Mutex sync.Mutex + Status int64 + Listener *conn.Listener // accept new connection from remote users + CtlMsgChan chan int64 // every time accept a new user conn, put "1" to the channel + CliConnChan chan *conn.Conn // get client conns from control goroutine + UserConnList *list.List // store user conns + Mutex sync.Mutex } func (p *ProxyServer) Init() { @@ -55,7 +55,7 @@ func (p *ProxyServer) Start() (err error) { go func() { for { // block - c := p.Listener.GetConn() + c := p.Listener.GetConn() log.Debug("ProxyName [%s], get one new user conn [%s]", p.Name, c.GetRemoteAddr()) // put to list @@ -93,7 +93,7 @@ func (p *ProxyServer) Start() (err error) { // msg will transfer to another without modifying log.Debug("Join two conns, (l[%s] r[%s]) (l[%s] r[%s])", cliConn.GetLocalAddr(), cliConn.GetRemoteAddr(), - userConn.GetLocalAddr(), userConn.GetRemoteAddr()) + userConn.GetLocalAddr(), userConn.GetRemoteAddr()) go conn.Join(cliConn, userConn) } }() @@ -112,5 +112,5 @@ func (p *ProxyServer) Close() { func (p *ProxyServer) WaitUserConn() (res int64) { res = <-p.CtlMsgChan - return + return } diff --git a/pkg/utils/conn/conn.go b/pkg/utils/conn/conn.go index b600f39..f8e352f 100644 --- a/pkg/utils/conn/conn.go +++ b/pkg/utils/conn/conn.go @@ -1,18 +1,18 @@ package conn import ( - "fmt" - "net" "bufio" - "sync" + "fmt" "io" + "net" + "sync" "github.com/fatedier/frp/pkg/utils/log" ) type Listener struct { - Addr net.Addr - Conns chan *Conn + Addr net.Addr + Conns chan *Conn } // wait util get one @@ -22,8 +22,8 @@ func (l *Listener) GetConn() (conn *Conn) { } type Conn struct { - TcpConn *net.TCPConn - Reader *bufio.Reader + TcpConn *net.TCPConn + Reader *bufio.Reader } func (c *Conn) ConnectServer(host string, port int64) (err error) { @@ -70,8 +70,8 @@ func Listen(bindAddr string, bindPort int64) (l *Listener, err error) { } l = &Listener{ - Addr: listener.Addr(), - Conns: make(chan *Conn), + Addr: listener.Addr(), + Conns: make(chan *Conn), } go func() { @@ -83,7 +83,7 @@ func Listen(bindAddr string, bindPort int64) (l *Listener, err error) { } c := &Conn{ - TcpConn: conn, + TcpConn: conn, } c.Reader = bufio.NewReader(c.TcpConn) l.Conns <- c diff --git a/pkg/utils/log/log.go b/pkg/utils/log/log.go index 1a55c3c..f6587cd 100644 --- a/pkg/utils/log/log.go +++ b/pkg/utils/log/log.go @@ -22,7 +22,7 @@ func SetLogFile(logWay string, logFile string) { if logWay == "console" { Log.SetLogger("console", "") } else { - Log.SetLogger("file", `{"filename": "` + logFile + `"}`) + Log.SetLogger("file", `{"filename": "`+logFile+`"}`) } }