http lint

This commit is contained in:
Michael Quigley 2022-08-10 15:16:36 -04:00
parent 6698cb98d7
commit cec12d5827
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 29 additions and 35 deletions

View File

@ -1,7 +0,0 @@
package http
type Config struct {
IdentityPath string
EndpointAddress string
Service string
}

View File

@ -6,10 +6,19 @@ import (
"github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net/http"
"net/http/httputil"
"net/url"
"time"
)
type Config struct {
IdentityPath string
EndpointAddress string
Service string
}
type httpProxy struct {
Requests func() int32
listener edge.Listener
@ -49,3 +58,23 @@ func (p *httpProxy) Run() error {
}
return nil
}
func NewProxy(target string) (*httputil.ReverseProxy, error) {
targetURL, err := url.Parse(target)
if err != nil {
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(targetURL)
director := proxy.Director
proxy.Director = func(req *http.Request) {
director(req)
logrus.Debugf("-> %v", req.URL.String())
req.Header.Set("X-Proxy", "zrok")
}
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
logrus.Errorf("error proxying: %v", err)
}
return proxy, nil
}

View File

@ -1,28 +0,0 @@
package http
import (
"github.com/sirupsen/logrus"
"net/http"
"net/http/httputil"
"net/url"
)
func NewProxy(target string) (*httputil.ReverseProxy, error) {
targetURL, err := url.Parse(target)
if err != nil {
return nil, err
}
proxy := httputil.NewSingleHostReverseProxy(targetURL)
director := proxy.Director
proxy.Director = func(req *http.Request) {
director(req)
logrus.Debugf("-> %v", req.URL.String())
req.Header.Set("X-Proxy", "zrok")
}
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
logrus.Errorf("error proxying: %v", err)
}
return proxy, nil
}