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