mirror of
https://github.com/openziti/zrok.git
synced 2025-04-02 18:46:05 +02:00
wiring in the go-swagger infrastructure
This commit is contained in:
parent
87d729791a
commit
ad8000c369
@ -23,13 +23,13 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
api := operations.NewZrokClientAPI(swaggerSpec)
|
api := operations.NewZrokAPI(swaggerSpec)
|
||||||
server := rest_zrok_server.NewServer(api)
|
server := rest_zrok_server.NewServer(api)
|
||||||
defer server.Shutdown()
|
defer server.Shutdown()
|
||||||
|
|
||||||
parser := flags.NewParser(server, flags.Default)
|
parser := flags.NewParser(server, flags.Default)
|
||||||
parser.ShortDescription = "zrok Client"
|
parser.ShortDescription = "zrok"
|
||||||
parser.LongDescription = "Client access service"
|
parser.LongDescription = "zrok client access"
|
||||||
server.ConfigureFlags()
|
server.ConfigureFlags()
|
||||||
for _, optsGroup := range api.CommandLineOptionsGroups {
|
for _, optsGroup := range api.CommandLineOptionsGroups {
|
||||||
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
|
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
|
@ -36,7 +36,7 @@ var controllerCmd = &cobra.Command{
|
|||||||
Short: "Start a zrok controller",
|
Short: "Start a zrok controller",
|
||||||
Aliases: []string{"ctrl"},
|
Aliases: []string{"ctrl"},
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
if err := controller.Run(&controller.Config{ApiEndpoint: "0.0.0.0:18888"}); err != nil {
|
if err := controller.Run(&controller.Config{Host: "0.0.0.0", Port: 10888}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -56,7 +56,7 @@ var proxyCmd = &cobra.Command{
|
|||||||
Use: "proxy <configPath>",
|
Use: "proxy <configPath>",
|
||||||
Short: "Start a zrok proxy",
|
Short: "Start a zrok proxy",
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
if err := proxy.Run(&proxy.Config{IdentityPath: args[0], Address: "0.0.0.0:10081"}); err != nil {
|
if err := proxy.Run(&proxy.Config{IdentityPath: args[0], Address: "0.0.0.0:10111"}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ApiEndpoint string
|
Host string
|
||||||
|
Port int
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-openapi/loads"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/rest_zrok_server"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
func Run(cfg *Config) error {
|
func Run(cfg *Config) error {
|
||||||
|
swaggerSpec, err := loads.Embedded(rest_zrok_server.SwaggerJSON, rest_zrok_server.FlatSwaggerJSON)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error loading embedded swagger spec")
|
||||||
|
}
|
||||||
|
|
||||||
|
api := operations.NewZrokAPI(swaggerSpec)
|
||||||
|
server := rest_zrok_server.NewServer(api)
|
||||||
|
defer func() { _ = server.Shutdown() }()
|
||||||
|
server.Host = cfg.Host
|
||||||
|
server.Port = cfg.Port
|
||||||
|
server.ConfigureAPI()
|
||||||
|
if err := server.Serve(); err != nil {
|
||||||
|
return errors.Wrap(err, "api server error")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func NewGetOK() *GetOK {
|
|||||||
|
|
||||||
/* GetOK describes a response with status code 200, with default header values.
|
/* GetOK describes a response with status code 200, with default header values.
|
||||||
|
|
||||||
Retrieve the current server version
|
retrieve the current server version
|
||||||
*/
|
*/
|
||||||
type GetOK struct {
|
type GetOK struct {
|
||||||
Payload *rest_model.Version
|
Payload *rest_model.Version
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/openziti-test-kitchen/zrok/rest_zrok_client/metadata"
|
"github.com/openziti-test-kitchen/zrok/rest_zrok_client/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default zrok client HTTP client.
|
// Default zrok HTTP client.
|
||||||
var Default = NewHTTPClient(nil)
|
var Default = NewHTTPClient(nil)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -28,14 +28,14 @@ const (
|
|||||||
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
|
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
|
||||||
var DefaultSchemes = []string{"http"}
|
var DefaultSchemes = []string{"http"}
|
||||||
|
|
||||||
// NewHTTPClient creates a new zrok client HTTP client.
|
// NewHTTPClient creates a new zrok HTTP client.
|
||||||
func NewHTTPClient(formats strfmt.Registry) *ZrokClient {
|
func NewHTTPClient(formats strfmt.Registry) *Zrok {
|
||||||
return NewHTTPClientWithConfig(formats, nil)
|
return NewHTTPClientWithConfig(formats, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPClientWithConfig creates a new zrok client HTTP client,
|
// NewHTTPClientWithConfig creates a new zrok HTTP client,
|
||||||
// using a customizable transport config.
|
// using a customizable transport config.
|
||||||
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *ZrokClient {
|
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Zrok {
|
||||||
// ensure nullable parameters have default
|
// ensure nullable parameters have default
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
cfg = DefaultTransportConfig()
|
cfg = DefaultTransportConfig()
|
||||||
@ -46,14 +46,14 @@ func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Zro
|
|||||||
return New(transport, formats)
|
return New(transport, formats)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new zrok client client
|
// New creates a new zrok client
|
||||||
func New(transport runtime.ClientTransport, formats strfmt.Registry) *ZrokClient {
|
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Zrok {
|
||||||
// ensure nullable parameters have default
|
// ensure nullable parameters have default
|
||||||
if formats == nil {
|
if formats == nil {
|
||||||
formats = strfmt.Default
|
formats = strfmt.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
cli := new(ZrokClient)
|
cli := new(Zrok)
|
||||||
cli.Transport = transport
|
cli.Transport = transport
|
||||||
cli.Metadata = metadata.New(transport, formats)
|
cli.Metadata = metadata.New(transport, formats)
|
||||||
return cli
|
return cli
|
||||||
@ -98,15 +98,15 @@ func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
|
|||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZrokClient is a client for zrok client
|
// Zrok is a client for zrok
|
||||||
type ZrokClient struct {
|
type Zrok struct {
|
||||||
Metadata metadata.ClientService
|
Metadata metadata.ClientService
|
||||||
|
|
||||||
Transport runtime.ClientTransport
|
Transport runtime.ClientTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTransport changes the transport on the client and all its subresources
|
// SetTransport changes the transport on the client and all its subresources
|
||||||
func (c *ZrokClient) SetTransport(transport runtime.ClientTransport) {
|
func (c *Zrok) SetTransport(transport runtime.ClientTransport) {
|
||||||
c.Transport = transport
|
c.Transport = transport
|
||||||
c.Metadata.SetTransport(transport)
|
c.Metadata.SetTransport(transport)
|
||||||
}
|
}
|
@ -14,13 +14,13 @@ import (
|
|||||||
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
|
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate swagger generate server --target ../../zrok --name ZrokClient --spec ../specs/zrok.yml --model-package rest_model --server-package rest_zrok_server --principal interface{}
|
//go:generate swagger generate server --target ../../zrok --name Zrok --spec ../specs/zrok.yml --model-package rest_model --server-package rest_zrok_server --principal interface{}
|
||||||
|
|
||||||
func configureFlags(api *operations.ZrokClientAPI) {
|
func configureFlags(api *operations.ZrokAPI) {
|
||||||
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
|
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureAPI(api *operations.ZrokClientAPI) http.Handler {
|
func configureAPI(api *operations.ZrokAPI) http.Handler {
|
||||||
// configure the api here
|
// configure the api here
|
||||||
api.ServeError = errors.ServeError
|
api.ServeError = errors.ServeError
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
// Code generated by go-swagger; DO NOT EDIT.
|
// Code generated by go-swagger; DO NOT EDIT.
|
||||||
|
|
||||||
// Package rest_zrok_server zrok Client
|
// Package rest_zrok_server zrok
|
||||||
//
|
//
|
||||||
// Client access service
|
// zrok client access
|
||||||
// Schemes:
|
// Schemes:
|
||||||
// http
|
// http
|
||||||
// Host: localhost
|
// Host: localhost
|
||||||
|
@ -29,8 +29,8 @@ func init() {
|
|||||||
],
|
],
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "Client access service",
|
"description": "zrok client access",
|
||||||
"title": "zrok Client",
|
"title": "zrok",
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
@ -41,7 +41,7 @@ func init() {
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Retrieve the current server version",
|
"description": "retrieve the current server version",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/version"
|
"$ref": "#/definitions/version"
|
||||||
}
|
}
|
||||||
@ -74,8 +74,8 @@ func init() {
|
|||||||
],
|
],
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "Client access service",
|
"description": "zrok client access",
|
||||||
"title": "zrok Client",
|
"title": "zrok",
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
},
|
},
|
||||||
"paths": {
|
"paths": {
|
||||||
@ -86,7 +86,7 @@ func init() {
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Retrieve the current server version",
|
"description": "retrieve the current server version",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/version"
|
"$ref": "#/definitions/version"
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
// GetOKCode is the HTTP code returned for type GetOK
|
// GetOKCode is the HTTP code returned for type GetOK
|
||||||
const GetOKCode int = 200
|
const GetOKCode int = 200
|
||||||
|
|
||||||
/*GetOK Retrieve the current server version
|
/*GetOK retrieve the current server version
|
||||||
|
|
||||||
swagger:response getOK
|
swagger:response getOK
|
||||||
*/
|
*/
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
|
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewZrokClientAPI creates a new ZrokClient instance
|
// NewZrokAPI creates a new Zrok instance
|
||||||
func NewZrokClientAPI(spec *loads.Document) *ZrokClientAPI {
|
func NewZrokAPI(spec *loads.Document) *ZrokAPI {
|
||||||
return &ZrokClientAPI{
|
return &ZrokAPI{
|
||||||
handlers: make(map[string]map[string]http.Handler),
|
handlers: make(map[string]map[string]http.Handler),
|
||||||
formats: strfmt.Default,
|
formats: strfmt.Default,
|
||||||
defaultConsumes: "application/json",
|
defaultConsumes: "application/json",
|
||||||
@ -50,8 +50,8 @@ func NewZrokClientAPI(spec *loads.Document) *ZrokClientAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*ZrokClientAPI Client access service */
|
/*ZrokAPI zrok client access */
|
||||||
type ZrokClientAPI struct {
|
type ZrokAPI struct {
|
||||||
spec *loads.Document
|
spec *loads.Document
|
||||||
context *middleware.Context
|
context *middleware.Context
|
||||||
handlers map[string]map[string]http.Handler
|
handlers map[string]map[string]http.Handler
|
||||||
@ -106,52 +106,52 @@ type ZrokClientAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UseRedoc for documentation at /docs
|
// UseRedoc for documentation at /docs
|
||||||
func (o *ZrokClientAPI) UseRedoc() {
|
func (o *ZrokAPI) UseRedoc() {
|
||||||
o.useSwaggerUI = false
|
o.useSwaggerUI = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseSwaggerUI for documentation at /docs
|
// UseSwaggerUI for documentation at /docs
|
||||||
func (o *ZrokClientAPI) UseSwaggerUI() {
|
func (o *ZrokAPI) UseSwaggerUI() {
|
||||||
o.useSwaggerUI = true
|
o.useSwaggerUI = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultProduces sets the default produces media type
|
// SetDefaultProduces sets the default produces media type
|
||||||
func (o *ZrokClientAPI) SetDefaultProduces(mediaType string) {
|
func (o *ZrokAPI) SetDefaultProduces(mediaType string) {
|
||||||
o.defaultProduces = mediaType
|
o.defaultProduces = mediaType
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaultConsumes returns the default consumes media type
|
// SetDefaultConsumes returns the default consumes media type
|
||||||
func (o *ZrokClientAPI) SetDefaultConsumes(mediaType string) {
|
func (o *ZrokAPI) SetDefaultConsumes(mediaType string) {
|
||||||
o.defaultConsumes = mediaType
|
o.defaultConsumes = mediaType
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSpec sets a spec that will be served for the clients.
|
// SetSpec sets a spec that will be served for the clients.
|
||||||
func (o *ZrokClientAPI) SetSpec(spec *loads.Document) {
|
func (o *ZrokAPI) SetSpec(spec *loads.Document) {
|
||||||
o.spec = spec
|
o.spec = spec
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultProduces returns the default produces media type
|
// DefaultProduces returns the default produces media type
|
||||||
func (o *ZrokClientAPI) DefaultProduces() string {
|
func (o *ZrokAPI) DefaultProduces() string {
|
||||||
return o.defaultProduces
|
return o.defaultProduces
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConsumes returns the default consumes media type
|
// DefaultConsumes returns the default consumes media type
|
||||||
func (o *ZrokClientAPI) DefaultConsumes() string {
|
func (o *ZrokAPI) DefaultConsumes() string {
|
||||||
return o.defaultConsumes
|
return o.defaultConsumes
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formats returns the registered string formats
|
// Formats returns the registered string formats
|
||||||
func (o *ZrokClientAPI) Formats() strfmt.Registry {
|
func (o *ZrokAPI) Formats() strfmt.Registry {
|
||||||
return o.formats
|
return o.formats
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterFormat registers a custom format validator
|
// RegisterFormat registers a custom format validator
|
||||||
func (o *ZrokClientAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
|
func (o *ZrokAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
|
||||||
o.formats.Add(name, format, validator)
|
o.formats.Add(name, format, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the registrations in the ZrokClientAPI
|
// Validate validates the registrations in the ZrokAPI
|
||||||
func (o *ZrokClientAPI) Validate() error {
|
func (o *ZrokAPI) Validate() error {
|
||||||
var unregistered []string
|
var unregistered []string
|
||||||
|
|
||||||
if o.JSONConsumer == nil {
|
if o.JSONConsumer == nil {
|
||||||
@ -174,23 +174,23 @@ func (o *ZrokClientAPI) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServeErrorFor gets a error handler for a given operation id
|
// ServeErrorFor gets a error handler for a given operation id
|
||||||
func (o *ZrokClientAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
|
func (o *ZrokAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
|
||||||
return o.ServeError
|
return o.ServeError
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthenticatorsFor gets the authenticators for the specified security schemes
|
// AuthenticatorsFor gets the authenticators for the specified security schemes
|
||||||
func (o *ZrokClientAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
|
func (o *ZrokAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authorizer returns the registered authorizer
|
// Authorizer returns the registered authorizer
|
||||||
func (o *ZrokClientAPI) Authorizer() runtime.Authorizer {
|
func (o *ZrokAPI) Authorizer() runtime.Authorizer {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsumersFor gets the consumers for the specified media types.
|
// ConsumersFor gets the consumers for the specified media types.
|
||||||
// MIME type parameters are ignored here.
|
// MIME type parameters are ignored here.
|
||||||
func (o *ZrokClientAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
|
func (o *ZrokAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
|
||||||
result := make(map[string]runtime.Consumer, len(mediaTypes))
|
result := make(map[string]runtime.Consumer, len(mediaTypes))
|
||||||
for _, mt := range mediaTypes {
|
for _, mt := range mediaTypes {
|
||||||
switch mt {
|
switch mt {
|
||||||
@ -207,7 +207,7 @@ func (o *ZrokClientAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Con
|
|||||||
|
|
||||||
// ProducersFor gets the producers for the specified media types.
|
// ProducersFor gets the producers for the specified media types.
|
||||||
// MIME type parameters are ignored here.
|
// MIME type parameters are ignored here.
|
||||||
func (o *ZrokClientAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
|
func (o *ZrokAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
|
||||||
result := make(map[string]runtime.Producer, len(mediaTypes))
|
result := make(map[string]runtime.Producer, len(mediaTypes))
|
||||||
for _, mt := range mediaTypes {
|
for _, mt := range mediaTypes {
|
||||||
switch mt {
|
switch mt {
|
||||||
@ -223,7 +223,7 @@ func (o *ZrokClientAPI) ProducersFor(mediaTypes []string) map[string]runtime.Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HandlerFor gets a http.Handler for the provided operation method and path
|
// HandlerFor gets a http.Handler for the provided operation method and path
|
||||||
func (o *ZrokClientAPI) HandlerFor(method, path string) (http.Handler, bool) {
|
func (o *ZrokAPI) HandlerFor(method, path string) (http.Handler, bool) {
|
||||||
if o.handlers == nil {
|
if o.handlers == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -238,8 +238,8 @@ func (o *ZrokClientAPI) HandlerFor(method, path string) (http.Handler, bool) {
|
|||||||
return h, ok
|
return h, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context returns the middleware context for the zrok client API
|
// Context returns the middleware context for the zrok API
|
||||||
func (o *ZrokClientAPI) Context() *middleware.Context {
|
func (o *ZrokAPI) Context() *middleware.Context {
|
||||||
if o.context == nil {
|
if o.context == nil {
|
||||||
o.context = middleware.NewRoutableContext(o.spec, o, nil)
|
o.context = middleware.NewRoutableContext(o.spec, o, nil)
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func (o *ZrokClientAPI) Context() *middleware.Context {
|
|||||||
return o.context
|
return o.context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ZrokClientAPI) initHandlerCache() {
|
func (o *ZrokAPI) initHandlerCache() {
|
||||||
o.Context() // don't care about the result, just that the initialization happened
|
o.Context() // don't care about the result, just that the initialization happened
|
||||||
if o.handlers == nil {
|
if o.handlers == nil {
|
||||||
o.handlers = make(map[string]map[string]http.Handler)
|
o.handlers = make(map[string]map[string]http.Handler)
|
||||||
@ -261,7 +261,7 @@ func (o *ZrokClientAPI) initHandlerCache() {
|
|||||||
|
|
||||||
// Serve creates a http handler to serve the API over HTTP
|
// Serve creates a http handler to serve the API over HTTP
|
||||||
// can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
|
// can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
|
||||||
func (o *ZrokClientAPI) Serve(builder middleware.Builder) http.Handler {
|
func (o *ZrokAPI) Serve(builder middleware.Builder) http.Handler {
|
||||||
o.Init()
|
o.Init()
|
||||||
|
|
||||||
if o.Middleware != nil {
|
if o.Middleware != nil {
|
||||||
@ -274,24 +274,24 @@ func (o *ZrokClientAPI) Serve(builder middleware.Builder) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
|
// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
|
||||||
func (o *ZrokClientAPI) Init() {
|
func (o *ZrokAPI) Init() {
|
||||||
if len(o.handlers) == 0 {
|
if len(o.handlers) == 0 {
|
||||||
o.initHandlerCache()
|
o.initHandlerCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterConsumer allows you to add (or override) a consumer for a media type.
|
// RegisterConsumer allows you to add (or override) a consumer for a media type.
|
||||||
func (o *ZrokClientAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
|
func (o *ZrokAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
|
||||||
o.customConsumers[mediaType] = consumer
|
o.customConsumers[mediaType] = consumer
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterProducer allows you to add (or override) a producer for a media type.
|
// RegisterProducer allows you to add (or override) a producer for a media type.
|
||||||
func (o *ZrokClientAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
|
func (o *ZrokAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
|
||||||
o.customProducers[mediaType] = producer
|
o.customProducers[mediaType] = producer
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMiddlewareFor adds a http middleware to existing handler
|
// AddMiddlewareFor adds a http middleware to existing handler
|
||||||
func (o *ZrokClientAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
|
func (o *ZrokAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
|
||||||
um := strings.ToUpper(method)
|
um := strings.ToUpper(method)
|
||||||
if path == "/" {
|
if path == "/" {
|
||||||
path = ""
|
path = ""
|
@ -42,8 +42,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new api zrok client server but does not configure it
|
// NewServer creates a new api zrok server but does not configure it
|
||||||
func NewServer(api *operations.ZrokClientAPI) *Server {
|
func NewServer(api *operations.ZrokAPI) *Server {
|
||||||
s := new(Server)
|
s := new(Server)
|
||||||
|
|
||||||
s.shutdown = make(chan struct{})
|
s.shutdown = make(chan struct{})
|
||||||
@ -66,14 +66,14 @@ func (s *Server) ConfigureFlags() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server for the zrok client API
|
// Server for the zrok API
|
||||||
type Server struct {
|
type Server struct {
|
||||||
EnabledListeners []string `long:"scheme" description:"the listeners to enable, this can be repeated and defaults to the schemes in the swagger spec"`
|
EnabledListeners []string `long:"scheme" description:"the listeners to enable, this can be repeated and defaults to the schemes in the swagger spec"`
|
||||||
CleanupTimeout time.Duration `long:"cleanup-timeout" description:"grace period for which to wait before killing idle connections" default:"10s"`
|
CleanupTimeout time.Duration `long:"cleanup-timeout" description:"grace period for which to wait before killing idle connections" default:"10s"`
|
||||||
GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"`
|
GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"`
|
||||||
MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"`
|
MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"`
|
||||||
|
|
||||||
SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/zrok-client.sock"`
|
SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/zrok.sock"`
|
||||||
domainSocketL net.Listener
|
domainSocketL net.Listener
|
||||||
|
|
||||||
Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"`
|
Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"`
|
||||||
@ -95,7 +95,7 @@ type Server struct {
|
|||||||
TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"`
|
TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"`
|
||||||
httpsServerL net.Listener
|
httpsServerL net.Listener
|
||||||
|
|
||||||
api *operations.ZrokClientAPI
|
api *operations.ZrokAPI
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
hasListeners bool
|
hasListeners bool
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
@ -125,7 +125,7 @@ func (s *Server) Fatalf(f string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetAPI configures the server with the specified API. Needs to be called before Serve
|
// SetAPI configures the server with the specified API. Needs to be called before Serve
|
||||||
func (s *Server) SetAPI(api *operations.ZrokClientAPI) {
|
func (s *Server) SetAPI(api *operations.ZrokAPI) {
|
||||||
if api == nil {
|
if api == nil {
|
||||||
s.api = nil
|
s.api = nil
|
||||||
s.handler = nil
|
s.handler = nil
|
||||||
@ -186,13 +186,13 @@ func (s *Server) Serve() (err error) {
|
|||||||
|
|
||||||
servers = append(servers, domainSocket)
|
servers = append(servers, domainSocket)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
s.Logf("Serving zrok client at unix://%s", s.SocketPath)
|
s.Logf("Serving zrok at unix://%s", s.SocketPath)
|
||||||
go func(l net.Listener) {
|
go func(l net.Listener) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := domainSocket.Serve(l); err != nil && err != http.ErrServerClosed {
|
if err := domainSocket.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||||
s.Fatalf("%v", err)
|
s.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
s.Logf("Stopped serving zrok client at unix://%s", s.SocketPath)
|
s.Logf("Stopped serving zrok at unix://%s", s.SocketPath)
|
||||||
}(s.domainSocketL)
|
}(s.domainSocketL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,13 +216,13 @@ func (s *Server) Serve() (err error) {
|
|||||||
|
|
||||||
servers = append(servers, httpServer)
|
servers = append(servers, httpServer)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
s.Logf("Serving zrok client at http://%s", s.httpServerL.Addr())
|
s.Logf("Serving zrok at http://%s", s.httpServerL.Addr())
|
||||||
go func(l net.Listener) {
|
go func(l net.Listener) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := httpServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
if err := httpServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||||
s.Fatalf("%v", err)
|
s.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
s.Logf("Stopped serving zrok client at http://%s", l.Addr())
|
s.Logf("Stopped serving zrok at http://%s", l.Addr())
|
||||||
}(s.httpServerL)
|
}(s.httpServerL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,13 +309,13 @@ func (s *Server) Serve() (err error) {
|
|||||||
|
|
||||||
servers = append(servers, httpsServer)
|
servers = append(servers, httpsServer)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
s.Logf("Serving zrok client at https://%s", s.httpsServerL.Addr())
|
s.Logf("Serving zrok at https://%s", s.httpsServerL.Addr())
|
||||||
go func(l net.Listener) {
|
go func(l net.Listener) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
if err := httpsServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
if err := httpsServer.Serve(l); err != nil && err != http.ErrServerClosed {
|
||||||
s.Fatalf("%v", err)
|
s.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
s.Logf("Stopped serving zrok client at https://%s", l.Addr())
|
s.Logf("Stopped serving zrok at https://%s", l.Addr())
|
||||||
}(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig))
|
}(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
info:
|
info:
|
||||||
description: Client access service
|
description: zrok client access
|
||||||
title: zrok Client
|
title: zrok
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
paths:
|
paths:
|
||||||
/:
|
/:
|
||||||
@ -9,7 +9,7 @@ paths:
|
|||||||
- metadata
|
- metadata
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Retrieve the current server version
|
description: retrieve the current server version
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/version"
|
$ref: "#/definitions/version"
|
||||||
definitions:
|
definitions:
|
||||||
|
Loading…
Reference in New Issue
Block a user