MCPcopy Create free account
hub / github.com/discourse/discourse-auth-proxy / main

Function main

main.go:42–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40)
41
42func main() {
43 {
44 var err error
45 config, err = ParseConfig()
46 if err != nil {
47 usage(err)
48 }
49 }
50
51 dnssrv := httpproxy.NewDNSSRVBackend(config.OriginURL)
52 go dnssrv.Lookup(context.Background(), 50*time.Second, 10*time.Second, config.SRVAbandonAfter)
53 proxy := &httputil.ReverseProxy{Director: dnssrv.Director}
54
55 handler := authProxyHandler(proxy)
56
57 if config.LogRequests {
58 handler = logHandler(handler)
59 }
60
61 var listener net.Listener
62 var err error
63
64 if strings.Index(config.ListenAddr, "unix:") == 0 {
65 file := strings.Replace(config.ListenAddr, "unix:", "", 1)
66 if _, err = os.Stat(file); err == nil {
67 os.Remove(file)
68 }
69 listener, err = net.Listen("unix", strings.Replace(config.ListenAddr, "unix:", "", 1))
70 } else {
71 listener, err = net.Listen("tcp", config.ListenAddr)
72 }
73
74 if err != nil {
75 log.Fatal(err)
76 }
77
78 server := &http.Server{
79 Handler: handler,
80 ReadTimeout: config.Timeout,
81 WriteTimeout: config.Timeout,
82 MaxHeaderBytes: 1 << 20,
83 }
84
85 log.Fatal(server.Serve(listener))
86}
87
88func authProxyHandler(handler http.Handler) http.Handler {
89 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 6

LookupMethod · 0.95
NewDNSSRVBackendFunction · 0.92
ParseConfigFunction · 0.85
usageFunction · 0.85
authProxyHandlerFunction · 0.85
logHandlerFunction · 0.85

Tested by

no test coverage detected