mirror of
https://github.com/fatedier/frp.git
synced 2026-01-11 22:23:12 +00:00
Use go fmt before build
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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+`"}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user