From 98512feda282c2138e0bad54eb491f00e1cd5105 Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 4 Mar 2025 17:18:36 -0700 Subject: refactor: collapse director and server into usage --- cmd/gtwy/main.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'cmd/gtwy') diff --git a/cmd/gtwy/main.go b/cmd/gtwy/main.go index 986741b..9b21c14 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()) } -- cgit v1.2.3