harbor/tools/swagger/templates/client/facade.gotmpl

84 lines
2.0 KiB
Go Template
Raw Normal View History

// Code generated by go-swagger; DO NOT EDIT.
{{ if .Copyright -}}// {{ comment .Copyright -}}{{ end }}
package {{ .Package }}
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/url"
"net/http"
rtclient "github.com/go-openapi/runtime/client"
"github.com/go-openapi/swag"
"github.com/go-openapi/spec"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
{{ imports .DefaultImports }}
{{ imports .Imports }}
)
const (
// DefaultHost is the default Host
// found in Meta (info) section of spec file
DefaultHost string = {{ printf "%#v" .Host }}
// DefaultBasePath is the default BasePath
// found in Meta (info) section of spec file
DefaultBasePath string = {{ printf "%#v" .BasePath }}
)
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = {{ printf "%#v" .Schemes }}
type Config struct {
// URL is the base URL of the upstream server
URL *url.URL
// Transport is an inner transport for the client
Transport http.RoundTripper
// AuthInfo is for authentication
AuthInfo runtime.ClientAuthInfoWriter
}
// New creates a new {{ humanize .Name }} HTTP client.
func New(c Config) *{{ pascalize .Name }} {
var (
host = DefaultHost
basePath = DefaultBasePath
schemes = DefaultSchemes
)
if c.URL != nil {
host = c.URL.Host
basePath = c.URL.Path
schemes = []string{c.URL.Scheme}
}
transport := rtclient.New(host, basePath, schemes)
if c.Transport != nil {
transport.Transport = c.Transport
}
cli := new({{ pascalize .Name }})
cli.Transport = transport
{{ range .OperationGroups -}}
cli.{{ pascalize .Name }} = {{ .PackageAlias }}.New(transport, strfmt.Default, c.AuthInfo)
{{ end -}}
return cli
}
// {{ pascalize .Name }} is a client for {{ humanize .Name }}
type {{ pascalize .Name }} struct {
{{ range .OperationGroups -}}
{{ pascalize .Name }} *{{ .PackageAlias }}.Client
{{ end -}}
Transport runtime.ClientTransport
}