github.com/djarvur/go-swagger@v0.18.0/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  	api.TasksAddCommentToTaskHandler = tasks.AddCommentToTaskHandlerFunc(func(params tasks.AddCommentToTaskParams, principal interface{}) middleware.Responder {
    54  		return middleware.NotImplemented("operation tasks.AddCommentToTask has not yet been implemented")
    55  	})
    56  	api.TasksCreateTaskHandler = tasks.CreateTaskHandlerFunc(func(params tasks.CreateTaskParams, principal interface{}) middleware.Responder {
    57  		return middleware.NotImplemented("operation tasks.CreateTask has not yet been implemented")
    58  	})
    59  	api.TasksDeleteTaskHandler = tasks.DeleteTaskHandlerFunc(func(params tasks.DeleteTaskParams, principal interface{}) middleware.Responder {
    60  		return middleware.NotImplemented("operation tasks.DeleteTask has not yet been implemented")
    61  	})
    62  	api.TasksGetTaskCommentsHandler = tasks.GetTaskCommentsHandlerFunc(func(params tasks.GetTaskCommentsParams) middleware.Responder {
    63  		return middleware.NotImplemented("operation tasks.GetTaskComments has not yet been implemented")
    64  	})
    65  	api.TasksGetTaskDetailsHandler = tasks.GetTaskDetailsHandlerFunc(func(params tasks.GetTaskDetailsParams) middleware.Responder {
    66  		return middleware.NotImplemented("operation tasks.GetTaskDetails has not yet been implemented")
    67  	})
    68  	api.TasksListTasksHandler = tasks.ListTasksHandlerFunc(func(params tasks.ListTasksParams) middleware.Responder {
    69  		return middleware.NotImplemented("operation tasks.ListTasks has not yet been implemented")
    70  	})
    71  	api.TasksUpdateTaskHandler = tasks.UpdateTaskHandlerFunc(func(params tasks.UpdateTaskParams, principal interface{}) middleware.Responder {
    72  		return middleware.NotImplemented("operation tasks.UpdateTask has not yet been implemented")
    73  	})
    74  	api.TasksUploadTaskFileHandler = tasks.UploadTaskFileHandlerFunc(func(params tasks.UploadTaskFileParams, principal interface{}) middleware.Responder {
    75  		return middleware.NotImplemented("operation tasks.UploadTaskFile has not yet been implemented")
    76  	})
    77  
    78  	api.ServerShutdown = func() {}
    79  
    80  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
    81  }
    82  
    83  // The TLS configuration before HTTPS server starts.
    84  func configureTLS(tlsConfig *tls.Config) {
    85  	// Make all necessary changes to the TLS configuration here.
    86  }
    87  
    88  // As soon as server is initialized but not run yet, this function will be called.
    89  // If you need to modify a config, store server instance to stop it individually later, this is the place.
    90  // This function can be called multiple times, depending on the number of serving schemes.
    91  // scheme value will be set accordingly: "http", "https" or "unix"
    92  func configureServer(s *http.Server, scheme, addr string) {
    93  }
    94  
    95  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
    96  // The middleware executes after routing but before authentication, binding and validation
    97  func setupMiddlewares(handler http.Handler) http.Handler {
    98  	return handler
    99  }
   100  
   101  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
   102  // So this is a good place to plug in a panic handling middleware, logging and metrics
   103  func setupGlobalMiddleware(handler http.Handler) http.Handler {
   104  	return handler
   105  }