github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/examples/tutorials/todo-list/server-2/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  	"github.com/go-openapi/errors"
    10  	"github.com/go-openapi/runtime"
    11  	"github.com/go-openapi/runtime/middleware"
    12  
    13  	"github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-2/restapi/operations"
    14  	"github.com/go-swagger/go-swagger/examples/tutorials/todo-list/server-2/restapi/operations/todos"
    15  )
    16  
    17  //go:generate swagger generate server --target ../../server-2 --name TodoList --spec ../swagger.yml --principal interface{}
    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.UseSwaggerUI()
    34  	// To continue using redoc as your UI, uncomment the following line
    35  	// api.UseRedoc()
    36  
    37  	api.JSONConsumer = runtime.JSONConsumer()
    38  
    39  	api.JSONProducer = runtime.JSONProducer()
    40  
    41  	if api.TodosAddOneHandler == nil {
    42  		api.TodosAddOneHandler = todos.AddOneHandlerFunc(func(params todos.AddOneParams) middleware.Responder {
    43  			return middleware.NotImplemented("operation todos.AddOne has not yet been implemented")
    44  		})
    45  	}
    46  	if api.TodosDestroyOneHandler == nil {
    47  		api.TodosDestroyOneHandler = todos.DestroyOneHandlerFunc(func(params todos.DestroyOneParams) middleware.Responder {
    48  			return middleware.NotImplemented("operation todos.DestroyOne has not yet been implemented")
    49  		})
    50  	}
    51  	if api.TodosFindTodosHandler == nil {
    52  		api.TodosFindTodosHandler = todos.FindTodosHandlerFunc(func(params todos.FindTodosParams) middleware.Responder {
    53  			return middleware.NotImplemented("operation todos.FindTodos has not yet been implemented")
    54  		})
    55  	}
    56  	if api.TodosUpdateOneHandler == nil {
    57  		api.TodosUpdateOneHandler = todos.UpdateOneHandlerFunc(func(params todos.UpdateOneParams) middleware.Responder {
    58  			return middleware.NotImplemented("operation todos.UpdateOne has not yet been implemented")
    59  		})
    60  	}
    61  
    62  	api.PreServerShutdown = func() {}
    63  
    64  	api.ServerShutdown = func() {}
    65  
    66  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
    67  }
    68  
    69  // The TLS configuration before HTTPS server starts.
    70  func configureTLS(tlsConfig *tls.Config) {
    71  	// Make all necessary changes to the TLS configuration here.
    72  }
    73  
    74  // As soon as server is initialized but not run yet, this function will be called.
    75  // If you need to modify a config, store server instance to stop it individually later, this is the place.
    76  // This function can be called multiple times, depending on the number of serving schemes.
    77  // scheme value will be set accordingly: "http", "https" or "unix".
    78  func configureServer(s *http.Server, scheme, addr string) {
    79  }
    80  
    81  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
    82  // The middleware executes after routing but before authentication, binding and validation.
    83  func setupMiddlewares(handler http.Handler) http.Handler {
    84  	return handler
    85  }
    86  
    87  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
    88  // So this is a good place to plug in a panic handling middleware, logging and metrics.
    89  func setupGlobalMiddleware(handler http.Handler) http.Handler {
    90  	return handler
    91  }