|
5 | 5 | "crypto/tls" |
6 | 6 | "crypto/x509" |
7 | 7 | "encoding/pem" |
| 8 | + "errors" |
8 | 9 | "fmt" |
9 | 10 | "log" |
10 | 11 | "net/http" |
@@ -164,31 +165,39 @@ func main() { |
164 | 165 | w.Header().Set("Content-Type", "application/pkix-crl") |
165 | 166 | pem.Encode(w, &pem.Block{Type: "X509 CRL", Bytes: crl.Raw}) |
166 | 167 | }) |
| 168 | + applicationRouter.HandleFunc("/ca", func(w http.ResponseWriter, r *http.Request) { |
| 169 | + w.Header().Set("Content-Type", "application/pkix-cert") |
| 170 | + w.Write(caCertificate.Raw) |
| 171 | + }) |
| 172 | + applicationRouter.HandleFunc("/ca.pem", func(w http.ResponseWriter, r *http.Request) { |
| 173 | + w.Header().Set("Content-Type", "application/x-x509-ca-cert") |
| 174 | + pem.Encode(w, &pem.Block{Type: "CERTIFICATE", Bytes: caCertificate.Raw}) |
| 175 | + }) |
167 | 176 |
|
168 | 177 | applicationServer := &http.Server{Addr: config.applicationListenAddress, Handler: metrics.Middleware(applicationRouter)} |
169 | | - metricsSever := &http.Server{Addr: config.metricsListenAddress, Handler: promhttp.Handler()} |
| 178 | + metricsServer := &http.Server{Addr: config.metricsListenAddress, Handler: promhttp.Handler()} |
170 | 179 |
|
171 | 180 | applicationServerClosed := make(chan any) |
172 | 181 | metricsServerClosed := make(chan any) |
173 | 182 | go func() { |
174 | 183 | log.Printf("starting application server on %+q", config.applicationListenAddress) |
175 | | - if listenError := applicationServer.ListenAndServe(); listenError != nil { |
| 184 | + if listenError := applicationServer.ListenAndServe(); !errors.Is(listenError, http.ErrServerClosed) { |
176 | 185 | log.Printf("application error: %v", listenError) |
177 | 186 | } |
178 | 187 | close(applicationServerClosed) |
179 | 188 | }() |
180 | 189 | go func() { |
181 | 190 | log.Printf("starting metrics server on %+q", config.metricsListenAddress) |
182 | | - if listenError := metricsSever.ListenAndServe(); listenError != nil { |
183 | | - log.Printf("metrics error: %v", listenError) |
| 191 | + if listenError := metricsServer.ListenAndServe(); !errors.Is(listenError, http.ErrServerClosed) { |
| 192 | + log.Printf("metrics server error: %v", listenError) |
184 | 193 | } |
185 | 194 | close(metricsServerClosed) |
186 | 195 | }() |
187 | 196 |
|
188 | 197 | <-signalChan |
189 | 198 | close(hupChan) |
190 | 199 | applicationServer.Shutdown(nil) |
191 | | - metricsSever.Shutdown(nil) |
| 200 | + metricsServer.Shutdown(nil) |
192 | 201 | <-applicationServerClosed |
193 | 202 | <-metricsServerClosed |
194 | 203 | } |
0 commit comments