MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / serve

Function serve

main.go:173–194  ·  view source on GitHub ↗
(cfg config.HTTP)

Source from the content-addressed store, hash-verified

171}
172
173func serve(cfg config.HTTP) {
174 var h http.Handler
175 ln := newListener(cfg.ListenAddr)
176
177 h = http.HandlerFunc(serveHTTP)
178 if cfg.ForceAutocertHandler {
179 if autocertManager == nil {
180 panic("BUG: autocertManager is not inited")
181 }
182 addr := ln.Addr().String()
183 parts := strings.Split(addr, ":")
184 if parts[len(parts)-1] != "80" {
185 log.Fatalf("`letsencrypt` specification requires http server to listen on :80 port to satisfy http-01 challenge. " +
186 "Otherwise, certificates will be impossible to generate")
187 }
188 h = autocertManager.HTTPHandler(h)
189 }
190 log.Infof("Serving http on %q", cfg.ListenAddr)
191 if err := listenAndServe(ln, h, cfg.TimeoutCfg); err != nil {
192 log.Fatalf("HTTP server error on %q: %s", cfg.ListenAddr, err)
193 }
194}
195
196func newServer(ln net.Listener, h http.Handler, cfg config.TimeoutCfg) *http.Server {
197 // nolint:gosec // We already configured ReadTimeout, so no need to set ReadHeaderTimeout as well.

Callers 1

mainFunction · 0.85

Calls 5

FatalfFunction · 0.92
InfofFunction · 0.92
newListenerFunction · 0.85
listenAndServeFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected