blob: 40c1126de9a7f835e66c9ecdb7f32d143e54312d [file] [edit]
{{/*
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.36.6/generator/templates/server/operation.gotmpl
*/}}
{{"// Code generated by go-swagger; DO NOT EDIT."}}
{{ if .Copyright -}}{{ lineComment .Copyright -}}{{ end }}
package {{ .Package }}
// ----------------------------------------------------------------------------
// Code generated by `swagger generate operation`.
//
// See hack/generate-swagger-api.sh
// ----------------------------------------------------------------------------
{{- if false }}{{/* TODO(moby): Disabled for moby/api */}}
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/conv"
"github.com/go-openapi/swag/jsonutils"
"github.com/go-openapi/swag/stringutils"
"github.com/go-openapi/swag/typeutils"
"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}
}
{{- $route := printf "%s swagger:route %s %s" (pascalize .Name) .Method .Path }}
{{- range .Tags }}{{ $route = printf "%s %s" $route . }}{{ end }}
{{- $route = printf "%s %s" $route (camelize .Name) }}
{{- $body := "" }}
{{- if .Summary }}{{ $body = .Summary }}{{ if .Description }}{{ $body = printf "%s\n\n%s" $body .Description }}{{ end }}
{{- else if .Description }}{{ $body = .Description }}
{{- else }}{{ $body = printf "%s %s API" (pascalize .Name) (humanize .Name) }}
{{- end }}
{{ lineComment $route }}
//
{{ lineComment $body }}
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
}
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 }}
{{ template "docstring" (dict "Ctx" . "Lead" (printf "%s " .GoName)) }}
//
// swagger:model {{ .Name }}
{{- template "schema" . }}
{{- end }}