Skip to content

Commit 8745654

Browse files
committed
Rename handler funcs
Signed-off-by: dusan <borovcanindusan1@gmail.com>
1 parent 8f78c4f commit 8745654

File tree

6 files changed

+14
-16
lines changed

6 files changed

+14
-16
lines changed

handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ type Handler interface {
77
// Name returns the protocol name.
88
Name() string
99

10-
// HandleClientData processes data from client to server.
10+
// ClientDataHandler processes data from client to server.
1111
// Returns modified data and whether to continue proxying.
12-
HandleClientData() HandleFunc
12+
ClientDataHandler() HandleFunc
1313

14-
// HandleServerData processes data from server to client.
14+
// ServerDataHandler processes data from server to client.
1515
// Returns modified data and whether to continue proxying.
16-
HandleServerData() HandleFunc
16+
ServerDataHandler() HandleFunc
1717

1818
// OnConnect is called when a new connection is established.
1919
OnConnect(ctx context.Context, conn ConnectionInfo) error

protocols/coap/protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (h *CoAPHandler) Detect(data []byte) bool {
3030
return version == 1
3131
}
3232

33-
func (h *CoAPHandler) HandleClientData() mgate.HandleFunc {
33+
func (h *CoAPHandler) ClientDataHandler() mgate.HandleFunc {
3434
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
3535
if h.logMessages && len(data) >= 4 {
3636
msgType := (data[0] >> 4) & 0x03
@@ -41,7 +41,7 @@ func (h *CoAPHandler) HandleClientData() mgate.HandleFunc {
4141
}
4242
}
4343

44-
func (h *CoAPHandler) HandleServerData() mgate.HandleFunc {
44+
func (h *CoAPHandler) ServerDataHandler() mgate.HandleFunc {
4545
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
4646
return data, true, nil
4747
}

protocols/http/protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (h *HTTPHandler) Detect(data []byte) bool {
3333
return false
3434
}
3535

36-
func (h *HTTPHandler) HandleClientData() mgate.HandleFunc {
36+
func (h *HTTPHandler) ClientDataHandler() mgate.HandleFunc {
3737
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
3838
if h.logRequests {
3939
lines := strings.Split(string(data), "\r\n")
@@ -45,7 +45,7 @@ func (h *HTTPHandler) HandleClientData() mgate.HandleFunc {
4545
}
4646
}
4747

48-
func (h *HTTPHandler) HandleServerData() mgate.HandleFunc {
48+
func (h *HTTPHandler) ServerDataHandler() mgate.HandleFunc {
4949
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
5050
return data, true, nil
5151
}

protocols/mqtt/protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (h *MQTTHandler) Detect(data []byte) bool {
3131
return packetType == 1
3232
}
3333

34-
func (h *MQTTHandler) HandleClientData() mgate.HandleFunc {
34+
func (h *MQTTHandler) ClientDataHandler() mgate.HandleFunc {
3535
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
3636
if h.logPackets && len(data) > 0 {
3737
packetType := data[0] >> 4
@@ -49,7 +49,7 @@ func (h *MQTTHandler) HandleClientData() mgate.HandleFunc {
4949
}
5050
}
5151

52-
func (h *MQTTHandler) HandleServerData() mgate.HandleFunc {
52+
func (h *MQTTHandler) ServerDataHandler() mgate.HandleFunc {
5353
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
5454
return data, true, nil
5555
}

protocols/nats/protocol.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (h *NATSHandler) Detect(data []byte) bool {
3535
bytes.HasPrefix(data, []byte("PING"))
3636
}
3737

38-
func (h *NATSHandler) HandleClientData() mgate.HandleFunc {
38+
func (h *NATSHandler) ClientDataHandler() mgate.HandleFunc {
3939
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
4040
if h.logOps {
4141
h.logNATSOperation(data, conn.Client.Addr, "->")
@@ -44,7 +44,7 @@ func (h *NATSHandler) HandleClientData() mgate.HandleFunc {
4444
}
4545
}
4646

47-
func (h *NATSHandler) HandleServerData() mgate.HandleFunc {
47+
func (h *NATSHandler) ServerDataHandler() mgate.HandleFunc {
4848
return func(ctx context.Context, data []byte, conn mgate.ConnectionInfo) ([]byte, bool, error) {
4949
if h.logOps {
5050
h.logNATSOperation(data, "Server", "<-")

tcp/proxy.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ func (p *TCPProxy) handleConnection(clientConn net.Conn) {
108108
// Client to Server
109109
go func() {
110110
defer wg.Done()
111-
p.pipe(clientConn, serverConn, p.handler.HandleClientData(), connInfo)
111+
p.pipe(clientConn, serverConn, p.handler.ClientDataHandler(), connInfo)
112112
}()
113113

114114
// Server to Client
115115
go func() {
116116
defer wg.Done()
117-
p.pipe(serverConn, clientConn, p.handler.HandleServerData(), connInfo)
117+
p.pipe(serverConn, clientConn, p.handler.ServerDataHandler(), connInfo)
118118
}()
119119

120120
wg.Wait()
@@ -162,5 +162,3 @@ func (p *TCPProxy) Stop() error {
162162
p.wg.Wait()
163163
return nil
164164
}
165-
166-
type handleFunc func(context.Context, []byte, mgate.ConnectionInfo) ([]byte, bool, error)

0 commit comments

Comments
 (0)