github.com/circl-dev/go-swagger@v0.31.0/examples/todo-list-strict/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/circl-dev/runtime"
    10  	"github.com/go-openapi/errors"
    11  
    12  	"github.com/circl-dev/go-swagger/examples/todo-list-strict/restapi/operations"
    13  	"github.com/circl-dev/go-swagger/examples/todo-list-strict/restapi/operations/todos"
    14  )
    15  
    16  //go:generate swagger generate server --target ../../todo-list-strict --name TodoList --spec ../swagger.yml --strict-responders
    17  
    18  func configureFlags(api *operations.TodoListAPI) {
    19  	// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
    20  }
    21  
    22  func configureAPI(api *operations.TodoListAPI) http.Handler {
    23  	// configure the api here
    24  	api.ServeError = errors.ServeError
    25  
    26  	// Set your custom logger if needed. Default one is log.Printf
    27  	// Expected interface func(string, ...interface{})
    28  	//
    29  	// Example:
    30  	// api.Logger = log.Printf
    31  
    32  	api.JSONConsumer = runtime.JSONConsumer()
    33  
    34  	api.JSONProducer = runtime.JSONProducer()
    35  
    36  	// Applies when the "x-todolist-token" header is set
    37  	if api.KeyAuth == nil {
    38  		api.KeyAuth = func(token string) (interface{}, error) {
    39  			return nil, errors.NotImplemented("api key auth (key) x-todolist-token from header param [x-todolist-token] has not yet been implemented")
    40  		}
    41  	}
    42  
    43  	// Set your custom authorizer if needed. Default one is security.Authorized()
    44  	// Expected interface runtime.Authorizer
    45  	//
    46  	// Example:
    47  	// api.APIAuthorizer = security.Authorized()
    48  	if api.TodosAddOneHandler == nil {
    49  		api.TodosAddOneHandler = todos.AddOneHandlerFunc(func(params todos.AddOneParams, principal interface{}) todos.AddOneResponder {
    50  			return todos.AddOneNotImplemented()
    51  		})
    52  	}
    53  	if api.TodosDestroyOneHandler == nil {
    54  		api.TodosDestroyOneHandler = todos.DestroyOneHandlerFunc(func(params todos.DestroyOneParams, principal interface{}) todos.DestroyOneResponder {
    55  			return todos.DestroyOneNotImplemented()
    56  		})
    57  	}
    58  	if api.TodosFindHandler == nil {
    59  		api.TodosFindHandler = todos.FindHandlerFunc(func(params todos.FindParams, principal interface{}) todos.FindResponder {
    60  			return todos.FindNotImplemented()
    61  		})
    62  	}
    63  	if api.TodosUpdateOneHandler == nil {
    64  		api.TodosUpdateOneHandler = todos.UpdateOneHandlerFunc(func(params todos.UpdateOneParams, principal interface{}) todos.UpdateOneResponder {
    65  			return todos.UpdateOneNotImplemented()
    66  		})
    67  	}
    68  
    69  	api.PreServerShutdown = func() {}
    70  
    71  	api.ServerShutdown = func() {}
    72  
    73  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
    74  }
    75  
    76  // The TLS configuration before HTTPS server starts.
    77  func configureTLS(tlsConfig *tls.Config) {
    78  	// Make all necessary changes to the TLS configuration here.
    79  }
    80  
    81  // As soon as server is initialized but not run yet, this function will be called.
    82  // If you need to modify a config, store server instance to stop it individually later, this is the place.
    83  // This function can be called multiple times, depending on the number of serving schemes.
    84  // scheme value will be set accordingly: "http", "https" or "unix".
    85  func configureServer(s *http.Server, scheme, addr string) {
    86  }
    87  
    88  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
    89  // The middleware executes after routing but before authentication, binding and validation.
    90  func setupMiddlewares(handler http.Handler) http.Handler {
    91  	return handler
    92  }
    93  
    94  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
    95  // So this is a good place to plug in a panic handling middleware, logging and metrics.
    96  func setupGlobalMiddleware(handler http.Handler) http.Handler {
    97  	return handler
    98  }