mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
135 lines
5.3 KiB
Go Template
135 lines
5.3 KiB
Go Template
{{/*
|
|
Custom "operation" template for Moby; it disables all code generation
|
|
and only produces the API structs.
|
|
|
|
The orignal template can be found at:
|
|
https://github.com/go-swagger/go-swagger/blob/v0.33.1/generator/templates/server/operation.gotmpl
|
|
*/}}
|
|
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
|
|
{{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }}
|
|
|
|
|
|
package {{ .Package }}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Code generated by `swagger generate operation`.
|
|
//
|
|
// See hack/generate-swagger-api.sh
|
|
// ----------------------------------------------------------------------------
|
|
{{- if false }}{{/* TODO(moby): Disabled for moby/api */}}
|
|
// This file was generated by the swagger tool.
|
|
// Editing this file might prove futile when you re-run the generate command
|
|
|
|
import (
|
|
"net/http"
|
|
{{- if .ExtraSchemas }}
|
|
stderrors "errors"
|
|
{{- end }}
|
|
|
|
"github.com/go-openapi/errors"
|
|
"github.com/go-openapi/runtime/middleware"
|
|
"github.com/go-openapi/runtime/security"
|
|
"github.com/go-openapi/strfmt"
|
|
"github.com/go-openapi/swag"
|
|
"github.com/go-openapi/validate"
|
|
|
|
{{ imports .DefaultImports }}
|
|
{{ imports .Imports }}
|
|
)
|
|
|
|
// {{ pascalize .Name }}HandlerFunc turns a function with the right signature into a {{ humanize .Name }} handler
|
|
type {{ pascalize .Name }}HandlerFunc func({{ pascalize .Name }}Params{{ if .Authorized }}, {{ if .PrincipalIsNullable }}*{{ end }}{{ .Principal }}{{ end }})
|
|
{{- if $.ReturnErrors }}
|
|
{{- if $.StrictResponders }} ({{ pascalize .Name }}Responder, error) {{else}} (middleware.Responder, error) {{end}}
|
|
{{ else }}
|
|
{{- if $.StrictResponders }} {{ pascalize .Name }}Responder {{else}} middleware.Responder {{end}}
|
|
{{ end }}
|
|
|
|
// Handle executing the request and returning a response
|
|
func (fn {{ pascalize .Name }}HandlerFunc) Handle(params {{ pascalize .Name }}Params{{ if .Authorized }}, principal {{ if .PrincipalIsNullable }}*{{ end }}{{ .Principal }}{{ end }})
|
|
{{- if $.ReturnErrors }}
|
|
{{- if $.StrictResponders }} ({{ pascalize .Name }}Responder, error) {{else}} (middleware.Responder, error) {{end}} {
|
|
{{ else }}
|
|
{{- if $.StrictResponders }} {{ pascalize .Name }}Responder {{else}} middleware.Responder {{end}} {
|
|
{{ end -}}
|
|
|
|
return fn(params{{ if .Authorized }}, principal{{ end }})
|
|
}
|
|
|
|
// {{ pascalize .Name }}Handler interface for that can handle valid {{ humanize .Name }} params
|
|
type {{ pascalize .Name }}Handler interface {
|
|
Handle({{ pascalize .Name }}Params{{ if .Authorized }}, {{ if .PrincipalIsNullable }}*{{ end }}{{ .Principal }}{{ end }})
|
|
{{- if $.ReturnErrors }}
|
|
{{- if $.StrictResponders }} ({{ pascalize .Name }}Responder, error) {{else}} (middleware.Responder, error) {{end}}
|
|
{{ else }}
|
|
{{- if $.StrictResponders }} {{ pascalize .Name }}Responder {{else}} middleware.Responder {{end}}
|
|
{{ end }}
|
|
}
|
|
|
|
// New{{ pascalize .Name }} creates a new http.Handler for the {{ humanize .Name }} operation
|
|
func New{{ pascalize .Name }}(ctx *middleware.Context, handler {{ pascalize .Name }}Handler) *{{ pascalize .Name }} {
|
|
return &{{ pascalize .Name }}{Context: ctx, Handler: handler}
|
|
}
|
|
|
|
/* {{ pascalize .Name }} swagger:route {{ .Method }} {{ .Path }}{{ range .Tags }} {{ . }}{{ end }} {{ camelize .Name }}
|
|
|
|
{{ if .Summary }}{{ .Summary }}{{ if .Description }}
|
|
|
|
{{ blockcomment .Description }}{{ end }}{{ else if .Description}}{{ blockcomment .Description }}{{ else }}{{ pascalize .Name }} {{ humanize .Name }} API{{ end }}
|
|
|
|
*/
|
|
type {{ pascalize .Name }} struct {
|
|
Context *middleware.Context
|
|
Handler {{ pascalize .Name }}Handler
|
|
}
|
|
|
|
func ({{ .ReceiverName }} *{{ pascalize .Name }}) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|
route, rCtx, _ := {{ .ReceiverName }}.Context.RouteInfo(r)
|
|
if rCtx != nil {
|
|
*r = *rCtx
|
|
}
|
|
var Params = New{{ pascalize .Name }}Params()
|
|
|
|
{{- if .Authorized }}
|
|
uprinc, aCtx, err := {{ .ReceiverName }}.Context.Authorize(r, route)
|
|
if err != nil {
|
|
{{ .ReceiverName }}.Context.Respond(rw, r, route.Produces, route, err)
|
|
return
|
|
}
|
|
if aCtx != nil {
|
|
*r = *aCtx
|
|
}
|
|
var principal {{ if .PrincipalIsNullable }}*{{ end }}{{ .Principal }}
|
|
if uprinc != nil {
|
|
principal = {{ if or (eq .Principal "inferface{}") (eq .Principal "any") }}uprinc{{ else }}uprinc.({{ if .PrincipalIsNullable }}*{{ end }}{{ .Principal }}) // this is really a {{ .Principal }}, I promise{{ end }}
|
|
}
|
|
{{ end }}
|
|
if err := {{ .ReceiverName }}.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
|
{{ .ReceiverName }}.Context.Respond(rw, r, route.Produces, route, err)
|
|
return
|
|
}
|
|
|
|
{{ if $.ReturnErrors }}
|
|
res, err := {{ .ReceiverName }}.Handler.Handle(Params{{ if .Authorized }}, principal{{ end }}) // actually handle the request
|
|
if err != nil {
|
|
{{ .ReceiverName }}.Context.Respond(rw, r, route.Produces, route, err)
|
|
return
|
|
}
|
|
{{ else }}
|
|
res := {{ .ReceiverName }}.Handler.Handle(Params{{ if .Authorized }}, principal{{ end }}) // actually handle the request
|
|
{{ end }}
|
|
|
|
{{ .ReceiverName }}.Context.Respond(rw, r, route.Produces, route, res)
|
|
|
|
}
|
|
{{- end }}{{/* TODO(moby): Disabled for moby/api */}}
|
|
|
|
{{ range .ExtraSchemas }}
|
|
// {{ .Name }} {{ comment .Description }}{{/* TODO(moby): workaround for "Name" included twice in godoc */}}
|
|
//
|
|
// swagger:model {{ .Name }}
|
|
{{- template "schema" . }}
|
|
{{- end }}
|