github.com/cilium/cilium@v1.16.2/api/v1/operator/server/configure_cilium_operator.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/operator/server/restapi" 17 "github.com/cilium/cilium/api/v1/operator/server/restapi/metrics" 18 "github.com/cilium/cilium/api/v1/operator/server/restapi/operator" 19 ) 20 21 //go:generate swagger generate server --target ../../operator --name CiliumOperator --spec ../openapi.yaml --api-package restapi --server-package server --principal interface{} 22 23 func configureFlags(api *restapi.CiliumOperatorAPI) { 24 // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } 25 } 26 27 func configureAPI(api *restapi.CiliumOperatorAPI) http.Handler { 28 // configure the api here 29 api.ServeError = errors.ServeError 30 31 // Set your custom logger if needed. Default one is log.Printf 32 // Expected interface func(string, ...interface{}) 33 // 34 // Example: 35 // api.Logger = log.Printf 36 37 api.UseSwaggerUI() 38 // To continue using redoc as your UI, uncomment the following line 39 // api.UseRedoc() 40 41 api.JSONConsumer = runtime.JSONConsumer() 42 43 api.JSONProducer = runtime.JSONProducer() 44 45 if api.OperatorGetHealthzHandler == nil { 46 api.OperatorGetHealthzHandler = operator.GetHealthzHandlerFunc(func(params operator.GetHealthzParams) middleware.Responder { 47 return middleware.NotImplemented("operation operator.GetHealthz has not yet been implemented") 48 }) 49 } 50 if api.MetricsGetMetricsHandler == nil { 51 api.MetricsGetMetricsHandler = metrics.GetMetricsHandlerFunc(func(params metrics.GetMetricsParams) middleware.Responder { 52 return middleware.NotImplemented("operation metrics.GetMetrics has not yet been implemented") 53 }) 54 } 55 56 api.PreServerShutdown = func() {} 57 58 api.ServerShutdown = func() {} 59 60 return setupGlobalMiddleware(api.Serve(setupMiddlewares)) 61 } 62 63 // The TLS configuration before HTTPS server starts. 64 func configureTLS(tlsConfig *tls.Config) { 65 // Make all necessary changes to the TLS configuration here. 66 } 67 68 // As soon as server is initialized but not run yet, this function will be called. 69 // If you need to modify a config, store server instance to stop it individually later, this is the place. 70 // This function can be called multiple times, depending on the number of serving schemes. 71 // scheme value will be set accordingly: "http", "https" or "unix" 72 func configureServer(s *http.Server, scheme, addr string) { 73 } 74 75 // The middleware configuration is for the handler executors. These do not apply to the swagger.json document. 76 // The middleware executes after routing but before authentication, binding and validation 77 func setupMiddlewares(handler http.Handler) http.Handler { 78 return handler 79 } 80 81 // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. 82 // So this is a good place to plug in a panic handling middleware, logging and metrics 83 func setupGlobalMiddleware(handler http.Handler) http.Handler { 84 return handler 85 }