github.com/emreu/go-swagger@v0.22.1/examples/tutorials/custom-server/gen/restapi/configure_greeter.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/tutorials/custom-server/gen/restapi/operations"
    14  )
    15  
    16  //go:generate swagger generate server --target ../../gen --name Greeter --spec ../../swagger/swagger.yml --exclude-main
    17  
    18  func configureFlags(api *operations.GreeterAPI) {
    19  	// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
    20  }
    21  
    22  func configureAPI(api *operations.GreeterAPI) 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.TxtProducer = runtime.TextProducer()
    35  
    36  	if api.GetGreetingHandler == nil {
    37  		api.GetGreetingHandler = operations.GetGreetingHandlerFunc(func(params operations.GetGreetingParams) middleware.Responder {
    38  			return middleware.NotImplemented("operation .GetGreeting has not yet been implemented")
    39  		})
    40  	}
    41  
    42  	api.ServerShutdown = func() {}
    43  
    44  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
    45  }
    46  
    47  // The TLS configuration before HTTPS server starts.
    48  func configureTLS(tlsConfig *tls.Config) {
    49  	// Make all necessary changes to the TLS configuration here.
    50  }
    51  
    52  // As soon as server is initialized but not run yet, this function will be called.
    53  // If you need to modify a config, store server instance to stop it individually later, this is the place.
    54  // This function can be called multiple times, depending on the number of serving schemes.
    55  // scheme value will be set accordingly: "http", "https" or "unix"
    56  func configureServer(s *http.Server, scheme, addr string) {
    57  }
    58  
    59  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
    60  // The middleware executes after routing but before authentication, binding and validation
    61  func setupMiddlewares(handler http.Handler) http.Handler {
    62  	return handler
    63  }
    64  
    65  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
    66  // So this is a good place to plug in a panic handling middleware, logging and metrics
    67  func setupGlobalMiddleware(handler http.Handler) http.Handler {
    68  	return handler
    69  }