configure_spaas.go 2.8 KB

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