-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.go
36 lines (31 loc) · 968 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package goproxy
import (
"github.com/autom8ter/api/go/api"
"github.com/autom8ter/goproxy/config"
"github.com/autom8ter/goproxy/httputil"
"net/http"
)
//GoProxy is a configurable single-target reverse-proxy HTTP handler compatible with the net/http http.Handler interface
type GoProxy struct {
r *httputil.ReverseProxy
config *config.Config
}
func (g *GoProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
g.r.ServeHTTP(w, r)
}
//NewGoProxy registers a new reverseproxy handler for each provided config with the specified path prefix
func NewGoProxy(config *config.Config) *GoProxy {
if err := api.Util.Validate(config); err != nil {
api.Util.Entry().Fatalln(err.Error())
}
return &GoProxy{
config: config,
r: &httputil.ReverseProxy{
Director: config.DirectorFunc(),
Transport: http.DefaultTransport,
FlushInterval: config.FlushInterval,
ErrorLog: config.Entry(),
ResponseHook: config.WebHook(),
},
}
}