github.com/emreu/go-swagger@v0.22.1/examples/task-tracker/restapi/configure_task_tracker.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/task-tracker/restapi/operations" 14 "github.com/go-swagger/go-swagger/examples/task-tracker/restapi/operations/tasks" 15 ) 16 17 //go:generate swagger generate server --target ../../task-tracker --name TaskTracker --spec ../swagger.yml 18 19 func configureFlags(api *operations.TaskTrackerAPI) { 20 // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } 21 } 22 23 func configureAPI(api *operations.TaskTrackerAPI) 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.MultipartformConsumer = runtime.DiscardConsumer 36 37 api.JSONProducer = runtime.JSONProducer() 38 39 // Applies when the "token" query is set 40 api.APIKeyAuth = func(token string) (interface{}, error) { 41 return nil, errors.NotImplemented("api key auth (api_key) token from query param [token] has not yet been implemented") 42 } 43 // Applies when the "X-Token" header is set 44 api.TokenHeaderAuth = func(token string) (interface{}, error) { 45 return nil, errors.NotImplemented("api key auth (token_header) X-Token from header param [X-Token] has not yet been implemented") 46 } 47 48 // Set your custom authorizer if needed. Default one is security.Authorized() 49 // Expected interface runtime.Authorizer 50 // 51 // Example: 52 // api.APIAuthorizer = security.Authorized() 53 if api.TasksAddCommentToTaskHandler == nil { 54 api.TasksAddCommentToTaskHandler = tasks.AddCommentToTaskHandlerFunc(func(params tasks.AddCommentToTaskParams, principal interface{}) middleware.Responder { 55 return middleware.NotImplemented("operation tasks.AddCommentToTask has not yet been implemented") 56 }) 57 } 58 if api.TasksCreateTaskHandler == nil { 59 api.TasksCreateTaskHandler = tasks.CreateTaskHandlerFunc(func(params tasks.CreateTaskParams, principal interface{}) middleware.Responder { 60 return middleware.NotImplemented("operation tasks.CreateTask has not yet been implemented") 61 }) 62 } 63 if api.TasksDeleteTaskHandler == nil { 64 api.TasksDeleteTaskHandler = tasks.DeleteTaskHandlerFunc(func(params tasks.DeleteTaskParams, principal interface{}) middleware.Responder { 65 return middleware.NotImplemented("operation tasks.DeleteTask has not yet been implemented") 66 }) 67 } 68 if api.TasksGetTaskCommentsHandler == nil { 69 api.TasksGetTaskCommentsHandler = tasks.GetTaskCommentsHandlerFunc(func(params tasks.GetTaskCommentsParams) middleware.Responder { 70 return middleware.NotImplemented("operation tasks.GetTaskComments has not yet been implemented") 71 }) 72 } 73 if api.TasksGetTaskDetailsHandler == nil { 74 api.TasksGetTaskDetailsHandler = tasks.GetTaskDetailsHandlerFunc(func(params tasks.GetTaskDetailsParams) middleware.Responder { 75 return middleware.NotImplemented("operation tasks.GetTaskDetails has not yet been implemented") 76 }) 77 } 78 if api.TasksListTasksHandler == nil { 79 api.TasksListTasksHandler = tasks.ListTasksHandlerFunc(func(params tasks.ListTasksParams) middleware.Responder { 80 return middleware.NotImplemented("operation tasks.ListTasks has not yet been implemented") 81 }) 82 } 83 if api.TasksUpdateTaskHandler == nil { 84 api.TasksUpdateTaskHandler = tasks.UpdateTaskHandlerFunc(func(params tasks.UpdateTaskParams, principal interface{}) middleware.Responder { 85 return middleware.NotImplemented("operation tasks.UpdateTask has not yet been implemented") 86 }) 87 } 88 if api.TasksUploadTaskFileHandler == nil { 89 api.TasksUploadTaskFileHandler = tasks.UploadTaskFileHandlerFunc(func(params tasks.UploadTaskFileParams, principal interface{}) middleware.Responder { 90 return middleware.NotImplemented("operation tasks.UploadTaskFile has not yet been implemented") 91 }) 92 } 93 94 api.ServerShutdown = func() {} 95 96 return setupGlobalMiddleware(api.Serve(setupMiddlewares)) 97 } 98 99 // The TLS configuration before HTTPS server starts. 100 func configureTLS(tlsConfig *tls.Config) { 101 // Make all necessary changes to the TLS configuration here. 102 } 103 104 // As soon as server is initialized but not run yet, this function will be called. 105 // If you need to modify a config, store server instance to stop it individually later, this is the place. 106 // This function can be called multiple times, depending on the number of serving schemes. 107 // scheme value will be set accordingly: "http", "https" or "unix" 108 func configureServer(s *http.Server, scheme, addr string) { 109 } 110 111 // The middleware configuration is for the handler executors. These do not apply to the swagger.json document. 112 // The middleware executes after routing but before authentication, binding and validation 113 func setupMiddlewares(handler http.Handler) http.Handler { 114 return handler 115 } 116 117 // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. 118 // So this is a good place to plug in a panic handling middleware, logging and metrics 119 func setupGlobalMiddleware(handler http.Handler) http.Handler { 120 return handler 121 }