github.com/cilium/cilium@v1.16.2/api/v1/health/server/configure_cilium_health_api.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 // This file is safe to edit. Once it exists it will not be overwritten 5 6 package server 7 8 import ( 9 "crypto/tls" 10 "net/http" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/runtime" 14 "github.com/go-openapi/runtime/middleware" 15 16 "github.com/cilium/cilium/api/v1/health/server/restapi" 17 "github.com/cilium/cilium/api/v1/health/server/restapi/connectivity" 18 ) 19 20 //go:generate swagger generate server --target ../../health --name CiliumHealthAPI --spec ../openapi.yaml --api-package restapi --server-package server --principal interface{} --default-scheme unix 21 22 func configureFlags(api *restapi.CiliumHealthAPIAPI) { 23 // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } 24 } 25 26 func configureAPI(api *restapi.CiliumHealthAPIAPI) http.Handler { 27 // configure the api here 28 api.ServeError = errors.ServeError 29 30 // Set your custom logger if needed. Default one is log.Printf 31 // Expected interface func(string, ...interface{}) 32 // 33 // Example: 34 // api.Logger = log.Printf 35 36 // api.UseSwaggerUI() 37 // To continue using redoc as your UI, uncomment the following line 38 // api.UseRedoc() 39 40 api.JSONConsumer = runtime.JSONConsumer() 41 42 api.JSONProducer = runtime.JSONProducer() 43 44 if api.GetHealthzHandler == nil { 45 api.GetHealthzHandler = restapi.GetHealthzHandlerFunc(func(params restapi.GetHealthzParams) middleware.Responder { 46 return middleware.NotImplemented("operation restapi.GetHealthz has not yet been implemented") 47 }) 48 } 49 if api.ConnectivityGetStatusHandler == nil { 50 api.ConnectivityGetStatusHandler = connectivity.GetStatusHandlerFunc(func(params connectivity.GetStatusParams) middleware.Responder { 51 return middleware.NotImplemented("operation connectivity.GetStatus has not yet been implemented") 52 }) 53 } 54 if api.ConnectivityPutStatusProbeHandler == nil { 55 api.ConnectivityPutStatusProbeHandler = connectivity.PutStatusProbeHandlerFunc(func(params connectivity.PutStatusProbeParams) middleware.Responder { 56 return middleware.NotImplemented("operation connectivity.PutStatusProbe has not yet been implemented") 57 }) 58 } 59 60 api.PreServerShutdown = func() {} 61 62 api.ServerShutdown = func() {} 63 64 return setupGlobalMiddleware(api.Serve(setupMiddlewares)) 65 } 66 67 // The TLS configuration before HTTPS server starts. 68 func configureTLS(tlsConfig *tls.Config) { 69 // Make all necessary changes to the TLS configuration here. 70 } 71 72 // As soon as server is initialized but not run yet, this function will be called. 73 // If you need to modify a config, store server instance to stop it individually later, this is the place. 74 // This function can be called multiple times, depending on the number of serving schemes. 75 // scheme value will be set accordingly: "http", "https" or "unix" 76 func configureServer(s *http.Server, scheme, addr string) { 77 } 78 79 // The middleware configuration is for the handler executors. These do not apply to the swagger.json document. 80 // The middleware executes after routing but before authentication, binding and validation 81 func setupMiddlewares(handler http.Handler) http.Handler { 82 return handler 83 } 84 85 // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. 86 // So this is a good place to plug in a panic handling middleware, logging and metrics 87 func setupGlobalMiddleware(handler http.Handler) http.Handler { 88 return handler 89 }