github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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/go-openapi/errors"
    10  	"github.com/go-openapi/runtime"
    11  	"github.com/go-openapi/runtime/middleware"
    12  
    13  	"github.com/thetreep/go-swagger/examples/task-tracker/restapi/operations"
    14  	"github.com/thetreep/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(
    65  			func(params tasks.AddCommentToTaskParams, principal interface{}) middleware.Responder {
    66  				return middleware.NotImplemented("operation tasks.AddCommentToTask has not yet been implemented")
    67  			},
    68  		)
    69  	}
    70  	if api.TasksCreateTaskHandler == nil {
    71  		api.TasksCreateTaskHandler = tasks.CreateTaskHandlerFunc(
    72  			func(params tasks.CreateTaskParams, principal interface{}) middleware.Responder {
    73  				return middleware.NotImplemented("operation tasks.CreateTask has not yet been implemented")
    74  			},
    75  		)
    76  	}
    77  	if api.TasksDeleteTaskHandler == nil {
    78  		api.TasksDeleteTaskHandler = tasks.DeleteTaskHandlerFunc(
    79  			func(params tasks.DeleteTaskParams, principal interface{}) middleware.Responder {
    80  				return middleware.NotImplemented("operation tasks.DeleteTask has not yet been implemented")
    81  			},
    82  		)
    83  	}
    84  	if api.TasksGetTaskCommentsHandler == nil {
    85  		api.TasksGetTaskCommentsHandler = tasks.GetTaskCommentsHandlerFunc(
    86  			func(params tasks.GetTaskCommentsParams) middleware.Responder {
    87  				return middleware.NotImplemented("operation tasks.GetTaskComments has not yet been implemented")
    88  			},
    89  		)
    90  	}
    91  	if api.TasksGetTaskDetailsHandler == nil {
    92  		api.TasksGetTaskDetailsHandler = tasks.GetTaskDetailsHandlerFunc(
    93  			func(params tasks.GetTaskDetailsParams) middleware.Responder {
    94  				return middleware.NotImplemented("operation tasks.GetTaskDetails has not yet been implemented")
    95  			},
    96  		)
    97  	}
    98  	if api.TasksListTasksHandler == nil {
    99  		api.TasksListTasksHandler = tasks.ListTasksHandlerFunc(
   100  			func(params tasks.ListTasksParams) middleware.Responder {
   101  				return middleware.NotImplemented("operation tasks.ListTasks has not yet been implemented")
   102  			},
   103  		)
   104  	}
   105  	if api.TasksUpdateTaskHandler == nil {
   106  		api.TasksUpdateTaskHandler = tasks.UpdateTaskHandlerFunc(
   107  			func(params tasks.UpdateTaskParams, principal interface{}) middleware.Responder {
   108  				return middleware.NotImplemented("operation tasks.UpdateTask has not yet been implemented")
   109  			},
   110  		)
   111  	}
   112  	if api.TasksUploadTaskFileHandler == nil {
   113  		api.TasksUploadTaskFileHandler = tasks.UploadTaskFileHandlerFunc(
   114  			func(params tasks.UploadTaskFileParams, principal interface{}) middleware.Responder {
   115  				return middleware.NotImplemented("operation tasks.UploadTaskFile has not yet been implemented")
   116  			},
   117  		)
   118  	}
   119  
   120  	api.PreServerShutdown = func() {}
   121  
   122  	api.ServerShutdown = func() {}
   123  
   124  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
   125  }
   126  
   127  // The TLS configuration before HTTPS server starts.
   128  func configureTLS(tlsConfig *tls.Config) {
   129  	// Make all necessary changes to the TLS configuration here.
   130  }
   131  
   132  // As soon as server is initialized but not run yet, this function will be called.
   133  // If you need to modify a config, store server instance to stop it individually later, this is the place.
   134  // This function can be called multiple times, depending on the number of serving schemes.
   135  // scheme value will be set accordingly: "http", "https" or "unix".
   136  func configureServer(s *http.Server, scheme, addr string) {
   137  }
   138  
   139  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
   140  // The middleware executes after routing but before authentication, binding and validation.
   141  func setupMiddlewares(handler http.Handler) http.Handler {
   142  	return handler
   143  }
   144  
   145  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
   146  // So this is a good place to plug in a panic handling middleware, logging and metrics.
   147  func setupGlobalMiddleware(handler http.Handler) http.Handler {
   148  	return handler
   149  }