diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-04 17:18:36 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-04 17:18:36 -0700 |
| commit | 98512feda282c2138e0bad54eb491f00e1cd5105 (patch) | |
| tree | 9b4352646158a77a37d32362f169fa979f11edd0 /cmd | |
| parent | 27f769137b5029098608df0dd8181fc678911f32 (diff) | |
refactor: collapse director and server into usage
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/gtwy/main.go | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/cmd/gtwy/main.go b/cmd/gtwy/main.go index 986741b0..9b21c149 100644 --- a/cmd/gtwy/main.go +++ b/cmd/gtwy/main.go @@ -10,16 +10,15 @@ import ( ) func NewProxy(from, to string) http.Handler { - director := func(r *http.Request) { - log.Printf("%v (from: %v to: %v)\n", r.URL, from, to) - r.URL.Scheme = "http" - r.Host = to - r.URL.Host = to - r.URL.Path = strings.TrimPrefix(r.URL.Path, strings.TrimSuffix(from, "/*")) - r.URL.RawPath = strings.TrimPrefix(r.URL.RawPath, strings.TrimSuffix(from, "/*")) - } return &httputil.ReverseProxy{ - Director: director, + Director: func(r *http.Request) { + log.Printf("%v (from: %v to: %v)\n", r.URL, from, to) + r.URL.Scheme = "http" + r.Host = to + r.URL.Host = to + r.URL.Path = strings.TrimPrefix(r.URL.Path, strings.TrimSuffix(from, "/*")) + r.URL.RawPath = strings.TrimPrefix(r.URL.RawPath, strings.TrimSuffix(from, "/*")) + }, Transport: http.DefaultTransport, FlushInterval: -1, ErrorLog: nil, @@ -38,7 +37,7 @@ func main() { mux.Handle("/idp/", NewProxy("/idp", "localhost:8282")) mux.Handle("/sp/", NewProxy("/sp", "localhost:8283")) - srv := &http.Server{ + log.Fatal((&http.Server{ Addr: ":8080", Handler: mux, ReadHeaderTimeout: 10 * time.Second, @@ -46,6 +45,5 @@ func main() { WriteTimeout: 2 * time.Minute, IdleTimeout: 5 * time.Minute, ErrorLog: log.Default(), - } - log.Fatal(srv.ListenAndServe()) + }).ListenAndServe()) } |
