From 3ec7e4253c1e6899a76ee5e161015f7db16dde05 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 14 Apr 2023 13:09:54 -0400 Subject: [PATCH] proxyBackend lint and cleanup (#170) --- cmd/zrok/sharePrivate.go | 2 +- cmd/zrok/sharePublic.go | 2 +- cmd/zrok/shareReserved.go | 2 +- endpoints/proxyBackend/http.go | 14 +++++++------- endpoints/tunnelBackend/tunnel.go | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 endpoints/tunnelBackend/tunnel.go diff --git a/cmd/zrok/sharePrivate.go b/cmd/zrok/sharePrivate.go index 2d4c1952..d0f75613 100644 --- a/cmd/zrok/sharePrivate.go +++ b/cmd/zrok/sharePrivate.go @@ -208,7 +208,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { } func (cmd *sharePrivateCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.NewBackend(cfg) + be, err := proxyBackend.New(cfg) if err != nil { return nil, errors.Wrap(err, "error creating http proxy backend") } diff --git a/cmd/zrok/sharePublic.go b/cmd/zrok/sharePublic.go index a3b2b4d7..88b27d95 100644 --- a/cmd/zrok/sharePublic.go +++ b/cmd/zrok/sharePublic.go @@ -210,7 +210,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { } func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.NewBackend(cfg) + be, err := proxyBackend.New(cfg) if err != nil { return nil, errors.Wrap(err, "error creating http proxy backend") } diff --git a/cmd/zrok/shareReserved.go b/cmd/zrok/shareReserved.go index a87cf023..5a1ff3f1 100644 --- a/cmd/zrok/shareReserved.go +++ b/cmd/zrok/shareReserved.go @@ -188,7 +188,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) { } func (cmd *shareReservedCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.NewBackend(cfg) + be, err := proxyBackend.New(cfg) if err != nil { return nil, errors.Wrap(err, "error creating http proxy backend") } diff --git a/endpoints/proxyBackend/http.go b/endpoints/proxyBackend/http.go index b2b73669..94b44bab 100644 --- a/endpoints/proxyBackend/http.go +++ b/endpoints/proxyBackend/http.go @@ -24,14 +24,14 @@ type Config struct { RequestsChan chan *endpoints.Request } -type backend struct { +type Backend struct { cfg *Config requests func() int32 listener edge.Listener handler http.Handler } -func NewBackend(cfg *Config) (*backend, error) { +func New(cfg *Config) (*Backend, error) { options := ziti.ListenOptions{ ConnectTimeout: 5 * time.Minute, MaxConnections: 64, @@ -51,7 +51,7 @@ func NewBackend(cfg *Config) (*backend, error) { } handler := util.NewProxyHandler(proxy) - return &backend{ + return &Backend{ cfg: cfg, requests: handler.Requests, listener: listener, @@ -59,15 +59,15 @@ func NewBackend(cfg *Config) (*backend, error) { }, nil } -func (self *backend) Run() error { - if err := http.Serve(self.listener, self.handler); err != nil { +func (b *Backend) Run() error { + if err := http.Serve(b.listener, b.handler); err != nil { return err } return nil } -func (self *backend) Requests() func() int32 { - return self.requests +func (b *Backend) Requests() func() int32 { + return b.requests } func newReverseProxy(cfg *Config) (*httputil.ReverseProxy, error) { diff --git a/endpoints/tunnelBackend/tunnel.go b/endpoints/tunnelBackend/tunnel.go new file mode 100644 index 00000000..27abec7b --- /dev/null +++ b/endpoints/tunnelBackend/tunnel.go @@ -0,0 +1,16 @@ +package tunnelBackend + +import "github.com/openziti/sdk-golang/ziti/edge" + +type Config struct { + IdentityPath string + EndpointAddress string + ShrToken string +} + +type Backend struct { + cfg *Config + listener edge.Listener +} + +func New \ No newline at end of file