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