github.com/djarvur/go-swagger@v0.18.0/examples/generated/restapi/configure_petstore.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/generated/restapi/operations"
    14  	"github.com/go-swagger/go-swagger/examples/generated/restapi/operations/pet"
    15  	"github.com/go-swagger/go-swagger/examples/generated/restapi/operations/store"
    16  	"github.com/go-swagger/go-swagger/examples/generated/restapi/operations/user"
    17  )
    18  
    19  //go:generate swagger generate server --target ../../generated --name Petstore --spec ../swagger.json
    20  
    21  func configureFlags(api *operations.PetstoreAPI) {
    22  	// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
    23  }
    24  
    25  func configureAPI(api *operations.PetstoreAPI) http.Handler {
    26  	// configure the api here
    27  	api.ServeError = errors.ServeError
    28  
    29  	// Set your custom logger if needed. Default one is log.Printf
    30  	// Expected interface func(string, ...interface{})
    31  	//
    32  	// Example:
    33  	// api.Logger = log.Printf
    34  
    35  	api.JSONConsumer = runtime.JSONConsumer()
    36  
    37  	api.UrlformConsumer = runtime.DiscardConsumer
    38  
    39  	api.XMLConsumer = runtime.XMLConsumer()
    40  
    41  	api.JSONProducer = runtime.JSONProducer()
    42  
    43  	api.XMLProducer = runtime.XMLProducer()
    44  
    45  	// Applies when the "api_key" header is set
    46  	api.APIKeyAuth = func(token string) (interface{}, error) {
    47  		return nil, errors.NotImplemented("api key auth (api_key) api_key from header param [api_key] has not yet been implemented")
    48  	}
    49  	api.PetstoreAuthAuth = func(token string, scopes []string) (interface{}, error) {
    50  		return nil, errors.NotImplemented("oauth2 bearer auth (petstore_auth) has not yet been implemented")
    51  	}
    52  
    53  	// Set your custom authorizer if needed. Default one is security.Authorized()
    54  	// Expected interface runtime.Authorizer
    55  	//
    56  	// Example:
    57  	// api.APIAuthorizer = security.Authorized()
    58  	api.PetAddPetHandler = pet.AddPetHandlerFunc(func(params pet.AddPetParams, principal interface{}) middleware.Responder {
    59  		return middleware.NotImplemented("operation pet.AddPet has not yet been implemented")
    60  	})
    61  	api.UserCreateUserHandler = user.CreateUserHandlerFunc(func(params user.CreateUserParams) middleware.Responder {
    62  		return middleware.NotImplemented("operation user.CreateUser has not yet been implemented")
    63  	})
    64  	api.UserCreateUsersWithArrayInputHandler = user.CreateUsersWithArrayInputHandlerFunc(func(params user.CreateUsersWithArrayInputParams) middleware.Responder {
    65  		return middleware.NotImplemented("operation user.CreateUsersWithArrayInput has not yet been implemented")
    66  	})
    67  	api.UserCreateUsersWithListInputHandler = user.CreateUsersWithListInputHandlerFunc(func(params user.CreateUsersWithListInputParams) middleware.Responder {
    68  		return middleware.NotImplemented("operation user.CreateUsersWithListInput has not yet been implemented")
    69  	})
    70  	api.StoreDeleteOrderHandler = store.DeleteOrderHandlerFunc(func(params store.DeleteOrderParams) middleware.Responder {
    71  		return middleware.NotImplemented("operation store.DeleteOrder has not yet been implemented")
    72  	})
    73  	api.PetDeletePetHandler = pet.DeletePetHandlerFunc(func(params pet.DeletePetParams, principal interface{}) middleware.Responder {
    74  		return middleware.NotImplemented("operation pet.DeletePet has not yet been implemented")
    75  	})
    76  	api.UserDeleteUserHandler = user.DeleteUserHandlerFunc(func(params user.DeleteUserParams) middleware.Responder {
    77  		return middleware.NotImplemented("operation user.DeleteUser has not yet been implemented")
    78  	})
    79  	api.PetFindPetsByStatusHandler = pet.FindPetsByStatusHandlerFunc(func(params pet.FindPetsByStatusParams, principal interface{}) middleware.Responder {
    80  		return middleware.NotImplemented("operation pet.FindPetsByStatus has not yet been implemented")
    81  	})
    82  	api.PetFindPetsByTagsHandler = pet.FindPetsByTagsHandlerFunc(func(params pet.FindPetsByTagsParams, principal interface{}) middleware.Responder {
    83  		return middleware.NotImplemented("operation pet.FindPetsByTags has not yet been implemented")
    84  	})
    85  	api.StoreGetOrderByIDHandler = store.GetOrderByIDHandlerFunc(func(params store.GetOrderByIDParams) middleware.Responder {
    86  		return middleware.NotImplemented("operation store.GetOrderByID has not yet been implemented")
    87  	})
    88  	api.PetGetPetByIDHandler = pet.GetPetByIDHandlerFunc(func(params pet.GetPetByIDParams, principal interface{}) middleware.Responder {
    89  		return middleware.NotImplemented("operation pet.GetPetByID has not yet been implemented")
    90  	})
    91  	api.UserGetUserByNameHandler = user.GetUserByNameHandlerFunc(func(params user.GetUserByNameParams) middleware.Responder {
    92  		return middleware.NotImplemented("operation user.GetUserByName has not yet been implemented")
    93  	})
    94  	api.UserLoginUserHandler = user.LoginUserHandlerFunc(func(params user.LoginUserParams) middleware.Responder {
    95  		return middleware.NotImplemented("operation user.LoginUser has not yet been implemented")
    96  	})
    97  	api.UserLogoutUserHandler = user.LogoutUserHandlerFunc(func(params user.LogoutUserParams) middleware.Responder {
    98  		return middleware.NotImplemented("operation user.LogoutUser has not yet been implemented")
    99  	})
   100  	api.StorePlaceOrderHandler = store.PlaceOrderHandlerFunc(func(params store.PlaceOrderParams) middleware.Responder {
   101  		return middleware.NotImplemented("operation store.PlaceOrder has not yet been implemented")
   102  	})
   103  	api.PetUpdatePetHandler = pet.UpdatePetHandlerFunc(func(params pet.UpdatePetParams, principal interface{}) middleware.Responder {
   104  		return middleware.NotImplemented("operation pet.UpdatePet has not yet been implemented")
   105  	})
   106  	api.PetUpdatePetWithFormHandler = pet.UpdatePetWithFormHandlerFunc(func(params pet.UpdatePetWithFormParams, principal interface{}) middleware.Responder {
   107  		return middleware.NotImplemented("operation pet.UpdatePetWithForm has not yet been implemented")
   108  	})
   109  	api.UserUpdateUserHandler = user.UpdateUserHandlerFunc(func(params user.UpdateUserParams) middleware.Responder {
   110  		return middleware.NotImplemented("operation user.UpdateUser has not yet been implemented")
   111  	})
   112  
   113  	api.ServerShutdown = func() {}
   114  
   115  	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
   116  }
   117  
   118  // The TLS configuration before HTTPS server starts.
   119  func configureTLS(tlsConfig *tls.Config) {
   120  	// Make all necessary changes to the TLS configuration here.
   121  }
   122  
   123  // As soon as server is initialized but not run yet, this function will be called.
   124  // If you need to modify a config, store server instance to stop it individually later, this is the place.
   125  // This function can be called multiple times, depending on the number of serving schemes.
   126  // scheme value will be set accordingly: "http", "https" or "unix"
   127  func configureServer(s *http.Server, scheme, addr string) {
   128  }
   129  
   130  // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
   131  // The middleware executes after routing but before authentication, binding and validation
   132  func setupMiddlewares(handler http.Handler) http.Handler {
   133  	return handler
   134  }
   135  
   136  // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
   137  // So this is a good place to plug in a panic handling middleware, logging and metrics
   138  func setupGlobalMiddleware(handler http.Handler) http.Handler {
   139  	return handler
   140  }