configure_spaas.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // This file is safe to edit. Once it exists it will not be overwritten
  2. package restapi
  3. import (
  4. "crypto/tls"
  5. "net/http"
  6. "github.com/go-openapi/errors"
  7. "github.com/go-openapi/runtime"
  8. "github.com/go-openapi/runtime/middleware"
  9. "gem-spaas-coding-challenge/restapi/operations"
  10. )
  11. //go:generate swagger generate server --target ../../gem-spaas-coding-challenge --name Spaas --spec ../swagger.yml --principal interface{}
  12. func configureFlags(api *operations.SpaasAPI) {
  13. // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
  14. }
  15. func configureAPI(api *operations.SpaasAPI) http.Handler {
  16. // configure the api here
  17. api.ServeError = errors.ServeError
  18. // Set your custom logger if needed. Default one is log.Printf
  19. // Expected interface func(string, ...interface{})
  20. //
  21. // Example:
  22. // api.Logger = log.Printf
  23. api.UseSwaggerUI()
  24. // To continue using redoc as your UI, uncomment the following line
  25. // api.UseRedoc()
  26. api.JSONConsumer = runtime.JSONConsumer()
  27. api.JSONProducer = runtime.JSONProducer()
  28. if api.ProductionPlanHandler == nil {
  29. api.ProductionPlanHandler = operations.ProductionPlanHandlerFunc(func(params operations.ProductionPlanParams) middleware.Responder {
  30. return middleware.NotImplemented("operation operations.ProductionPlan has not yet been implemented")
  31. })
  32. }
  33. api.PreServerShutdown = func() {}
  34. api.ServerShutdown = func() {}
  35. return setupGlobalMiddleware(api.Serve(setupMiddlewares))
  36. }
  37. // The TLS configuration before HTTPS server starts.
  38. func configureTLS(tlsConfig *tls.Config) {
  39. // Make all necessary changes to the TLS configuration here.
  40. }
  41. // As soon as server is initialized but not run yet, this function will be called.
  42. // If you need to modify a config, store server instance to stop it individually later, this is the place.
  43. // This function can be called multiple times, depending on the number of serving schemes.
  44. // scheme value will be set accordingly: "http", "https" or "unix".
  45. func configureServer(s *http.Server, scheme, addr string) {
  46. }
  47. // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
  48. // The middleware executes after routing but before authentication, binding and validation.
  49. func setupMiddlewares(handler http.Handler) http.Handler {
  50. return handler
  51. }
  52. // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
  53. // So this is a good place to plug in a panic handling middleware, logging and metrics.
  54. func setupGlobalMiddleware(handler http.Handler) http.Handler {
  55. return handler
  56. }