代码拉取完成,页面将自动刷新
package operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"net/http"
"strings"
loads "github.com/go-openapi/loads"
runtime "github.com/go-openapi/runtime"
middleware "github.com/go-openapi/runtime/middleware"
security "github.com/go-openapi/runtime/security"
spec "github.com/go-openapi/spec"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-swagger/go-swagger/examples/todo-list/restapi/operations/todos"
)
// NewTodoListAPI creates a new TodoList instance
func NewTodoListAPI(spec *loads.Document) *TodoListAPI {
return &TodoListAPI{
handlers: make(map[string]map[string]http.Handler),
formats: strfmt.Default,
defaultConsumes: "application/json",
defaultProduces: "application/json",
ServerShutdown: func() {},
spec: spec,
}
}
/*TodoListAPI the todo list API */
type TodoListAPI struct {
spec *loads.Document
context *middleware.Context
handlers map[string]map[string]http.Handler
formats strfmt.Registry
defaultConsumes string
defaultProduces string
Middleware func(middleware.Builder) http.Handler
// JSONConsumer registers a consumer for a "application/io.swagger.examples.todo-list.v1+json" mime type
JSONConsumer runtime.Consumer
// JSONProducer registers a producer for a "application/io.swagger.examples.todo-list.v1+json" mime type
JSONProducer runtime.Producer
// KeyAuth registers a function that takes a token and returns a principal
// it performs authentication based on an api key x-todolist-token provided in the header
KeyAuth func(string) (interface{}, error)
// TodosAddOneHandler sets the operation handler for the add one operation
TodosAddOneHandler todos.AddOneHandler
// TodosDestroyOneHandler sets the operation handler for the destroy one operation
TodosDestroyOneHandler todos.DestroyOneHandler
// TodosFindHandler sets the operation handler for the find operation
TodosFindHandler todos.FindHandler
// TodosUpdateOneHandler sets the operation handler for the update one operation
TodosUpdateOneHandler todos.UpdateOneHandler
// ServeError is called when an error is received, there is a default handler
// but you can set your own with this
ServeError func(http.ResponseWriter, *http.Request, error)
// ServerShutdown is called when the HTTP(S) server is shut down and done
// handling all active connections and does not accept connections any more
ServerShutdown func()
// Custom command line argument groups with their descriptions
CommandLineOptionsGroups []swag.CommandLineOptionsGroup
// User defined logger function.
Logger func(string, ...interface{})
}
// SetDefaultProduces sets the default produces media type
func (o *TodoListAPI) SetDefaultProduces(mediaType string) {
o.defaultProduces = mediaType
}
// SetDefaultConsumes returns the default consumes media type
func (o *TodoListAPI) SetDefaultConsumes(mediaType string) {
o.defaultConsumes = mediaType
}
// SetSpec sets a spec that will be served for the clients.
func (o *TodoListAPI) SetSpec(spec *loads.Document) {
o.spec = spec
}
// DefaultProduces returns the default produces media type
func (o *TodoListAPI) DefaultProduces() string {
return o.defaultProduces
}
// DefaultConsumes returns the default consumes media type
func (o *TodoListAPI) DefaultConsumes() string {
return o.defaultConsumes
}
// Formats returns the registered string formats
func (o *TodoListAPI) Formats() strfmt.Registry {
return o.formats
}
// RegisterFormat registers a custom format validator
func (o *TodoListAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
o.formats.Add(name, format, validator)
}
// Validate validates the registrations in the TodoListAPI
func (o *TodoListAPI) Validate() error {
var unregistered []string
if o.JSONConsumer == nil {
unregistered = append(unregistered, "JSONConsumer")
}
if o.JSONProducer == nil {
unregistered = append(unregistered, "JSONProducer")
}
if o.KeyAuth == nil {
unregistered = append(unregistered, "XTodolistTokenAuth")
}
if o.TodosAddOneHandler == nil {
unregistered = append(unregistered, "todos.AddOneHandler")
}
if o.TodosDestroyOneHandler == nil {
unregistered = append(unregistered, "todos.DestroyOneHandler")
}
if o.TodosFindHandler == nil {
unregistered = append(unregistered, "todos.FindHandler")
}
if o.TodosUpdateOneHandler == nil {
unregistered = append(unregistered, "todos.UpdateOneHandler")
}
if len(unregistered) > 0 {
return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
}
return nil
}
// ServeErrorFor gets a error handler for a given operation id
func (o *TodoListAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
return o.ServeError
}
// AuthenticatorsFor gets the authenticators for the specified security schemes
func (o *TodoListAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
result := make(map[string]runtime.Authenticator)
for name, scheme := range schemes {
switch name {
case "key":
result[name] = security.APIKeyAuth(scheme.Name, scheme.In, o.KeyAuth)
}
}
return result
}
// ConsumersFor gets the consumers for the specified media types
func (o *TodoListAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
result := make(map[string]runtime.Consumer)
for _, mt := range mediaTypes {
switch mt {
case "application/io.swagger.examples.todo-list.v1+json":
result["application/io.swagger.examples.todo-list.v1+json"] = o.JSONConsumer
}
}
return result
}
// ProducersFor gets the producers for the specified media types
func (o *TodoListAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
result := make(map[string]runtime.Producer)
for _, mt := range mediaTypes {
switch mt {
case "application/io.swagger.examples.todo-list.v1+json":
result["application/io.swagger.examples.todo-list.v1+json"] = o.JSONProducer
}
}
return result
}
// HandlerFor gets a http.Handler for the provided operation method and path
func (o *TodoListAPI) HandlerFor(method, path string) (http.Handler, bool) {
if o.handlers == nil {
return nil, false
}
um := strings.ToUpper(method)
if _, ok := o.handlers[um]; !ok {
return nil, false
}
h, ok := o.handlers[um][path]
return h, ok
}
// Context returns the middleware context for the todo list API
func (o *TodoListAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
}
func (o *TodoListAPI) initHandlerCache() {
o.Context() // don't care about the result, just that the initialization happened
if o.handlers == nil {
o.handlers = make(map[string]map[string]http.Handler)
}
if o.handlers["POST"] == nil {
o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler)
}
o.handlers["POST"]["/"] = todos.NewAddOne(o.context, o.TodosAddOneHandler)
if o.handlers["DELETE"] == nil {
o.handlers[strings.ToUpper("DELETE")] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/{id}"] = todos.NewDestroyOne(o.context, o.TodosDestroyOneHandler)
if o.handlers["GET"] == nil {
o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler)
}
o.handlers["GET"]["/"] = todos.NewFind(o.context, o.TodosFindHandler)
if o.handlers["PUT"] == nil {
o.handlers[strings.ToUpper("PUT")] = make(map[string]http.Handler)
}
o.handlers["PUT"]["/{id}"] = todos.NewUpdateOne(o.context, o.TodosUpdateOneHandler)
}
// Serve creates a http handler to serve the API over HTTP
// can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
func (o *TodoListAPI) Serve(builder middleware.Builder) http.Handler {
o.Init()
if o.Middleware != nil {
return o.Middleware(builder)
}
return o.context.APIHandler(builder)
}
// Init allows you to just initialize the handler cache, you can then recompose the middelware as you see fit
func (o *TodoListAPI) Init() {
if len(o.handlers) == 0 {
o.initHandlerCache()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。