Skip to content

Commit

Permalink
Rename Passer to Frowarder
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin committed Aug 6, 2024
1 parent 9c0ab0c commit cbce478
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

"github.com/absmach/mproxy"
"github.com/absmach/mproxy/examples/simple"
"github.com/absmach/mproxy/forwarder"
"github.com/absmach/mproxy/http"
"github.com/absmach/mproxy/mqtt"
"github.com/absmach/mproxy/mqtt/websocket"
"github.com/absmach/mproxy/passer"
"github.com/absmach/mproxy/streamer"
"github.com/caarlos0/env/v11"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -116,7 +116,7 @@ func main() {
// mProxy server for MQTT over Websocket without TLS
wsProxy := websocket.New(wsConfig.Target, handler, interceptor, logger)
g.Go(func() error {
return passer.Listen(ctx, "WS", wsConfig, wsProxy, logger)
return forwarder.Listen(ctx, "WS", wsConfig, wsProxy, logger)
})

// mProxy server Configuration for MQTT over Websocket with TLS
Expand All @@ -128,7 +128,7 @@ func main() {
// mProxy server for MQTT over Websocket with TLS
wsTLSProxy := websocket.New(wsTLSConfig.Target, handler, interceptor, logger)
g.Go(func() error {
return passer.Listen(ctx, "WS", wsTLSConfig, wsTLSProxy, logger)
return forwarder.Listen(ctx, "WS", wsTLSConfig, wsTLSProxy, logger)
})

// mProxy server Configuration for MQTT over Websocket with mTLS
Expand All @@ -140,7 +140,7 @@ func main() {
// mProxy server for MQTT over Websocket with mTLS
wsMTLSProxy := websocket.New(wsMTLSConfig.Target, handler, interceptor, logger)
g.Go(func() error {
return passer.Listen(ctx, "WS", wsMTLSConfig, wsMTLSProxy, logger)
return forwarder.Listen(ctx, "WS", wsMTLSConfig, wsMTLSProxy, logger)
})

// mProxy server Configuration for HTTP without TLS
Expand All @@ -155,7 +155,7 @@ func main() {
panic(err)
}
g.Go(func() error {
return passer.Listen(ctx, "HTTP", httpConfig, httpProxy, logger)
return forwarder.Listen(ctx, "HTTP", httpConfig, httpProxy, logger)
})

// mProxy server Configuration for HTTP with TLS
Expand All @@ -170,7 +170,7 @@ func main() {
panic(err)
}
g.Go(func() error {
return passer.Listen(ctx, "HTTP", httpTLSConfig, httpTLSProxy, logger)
return forwarder.Listen(ctx, "HTTP", httpTLSConfig, httpTLSProxy, logger)
})

// mProxy server Configuration for HTTP with mTLS
Expand All @@ -185,7 +185,7 @@ func main() {
panic(err)
}
g.Go(func() error {
return passer.Listen(ctx, "HTTP", httpMTLSConfig, httpMTLSProxy, logger)
return forwarder.Listen(ctx, "HTTP", httpMTLSConfig, httpMTLSProxy, logger)
})

g.Go(func() error {
Expand Down
6 changes: 3 additions & 3 deletions passer/proxy.go → forwarder/proxy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package passer
package forwarder

import (
"context"
Expand All @@ -16,7 +16,7 @@ import (
"golang.org/x/sync/errgroup"
)

func Listen(ctx context.Context, name string, config mproxy.Config, passer mproxy.Passer, logger *slog.Logger) error {
func Listen(ctx context.Context, name string, config mproxy.Config, passer mproxy.Forwarder, logger *slog.Logger) error {
l, err := net.Listen("tcp", config.Address)
if err != nil {
return err
Expand All @@ -33,7 +33,7 @@ func Listen(ctx context.Context, name string, config mproxy.Config, passer mprox
g, ctx := errgroup.WithContext(ctx)

mux := http.NewServeMux()
mux.HandleFunc(config.PathPrefix, passer.Pass)
mux.HandleFunc(config.PathPrefix, passer.Forward)
server.Handler = mux

g.Go(func() error {
Expand Down
4 changes: 2 additions & 2 deletions http/passer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type proxy struct {
logger *slog.Logger
}

func NewProxy(config mproxy.Config, handler mproxy.Handler, logger *slog.Logger) (mproxy.Passer, error) {
func NewProxy(config mproxy.Config, handler mproxy.Handler, logger *slog.Logger) (mproxy.Forwarder, error) {
target, err := url.Parse(config.Target)
if err != nil {
return proxy{}, err
Expand All @@ -44,7 +44,7 @@ func NewProxy(config mproxy.Config, handler mproxy.Handler, logger *slog.Logger)
}, nil
}

func (p proxy) Pass(w http.ResponseWriter, r *http.Request) {
func (p proxy) Forward(w http.ResponseWriter, r *http.Request) {
// Metrics and health endpoints are served directly.
if r.URL.Path == "/metrics" || r.URL.Path == "/health" {
p.target.ServeHTTP(w, r)
Expand Down
8 changes: 4 additions & 4 deletions mproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ type Streamer interface {
Stream(ctx context.Context, conn1, conn2 net.Conn) error
}

// Passer is used for request-response protocols.
type Passer interface {
// Pass forwards the HTTP request and response for HTTP and
// Forwarder is used for request-response protocols.
type Forwarder interface {
// Forward forwards the HTTP request and response for HTTP and
// WS based protocols.
Pass(rw http.ResponseWriter, r *http.Request)
Forward(rw http.ResponseWriter, r *http.Request)
}
4 changes: 2 additions & 2 deletions mqtt/websocket/passer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type proxy struct {
}

// New - creates new WS proxy passer.
func New(target string, handler mproxy.Handler, interceptor mproxy.Interceptor, logger *slog.Logger) mproxy.Passer {
func New(target string, handler mproxy.Handler, interceptor mproxy.Interceptor, logger *slog.Logger) mproxy.Forwarder {
return &proxy{
target: target,
handler: handler,
Expand All @@ -42,7 +42,7 @@ var upgrader = websocket.Upgrader{
},
}

func (p proxy) Pass(w http.ResponseWriter, r *http.Request) {
func (p proxy) Forward(w http.ResponseWriter, r *http.Request) {
cconn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
p.logger.Error("Error upgrading connection", slog.Any("error", err))
Expand Down
4 changes: 2 additions & 2 deletions websockets/passer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Proxy struct {
logger *slog.Logger
}

func (p *Proxy) Pass(w http.ResponseWriter, r *http.Request) {
func (p *Proxy) Forward(w http.ResponseWriter, r *http.Request) {
var token string
headers := http.Header{}
switch {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (p *Proxy) stream(ctx context.Context, topic string, src, dest *websocket.C
}
}

func NewProxy(target string, logger *slog.Logger, handler session.Handler) mproxy.Passer {
func NewProxy(target string, logger *slog.Logger, handler session.Handler) mproxy.Forwarder {
return &Proxy{
target: target,
logger: logger,
Expand Down

0 comments on commit cbce478

Please sign in to comment.