Skip to content
Snippets Groups Projects
Commit 94702dbb authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

V0.0.1

parent 73c1fdc2
No related branches found
No related tags found
No related merge requests found
Showing
with 1735 additions and 0 deletions
image: quay.io/goswagger/swagger:latest
before_script:
- mkdir .ssh
- echo $SSH_PRIVATE_KEY > .ssh/gitlab-ci
- echo "Host code.fbi.h-da.de" > .ssh/config
- echo " Hostname code.fbi.h-da.de" >> .ssh/config
- echo " User git" >> .ssh/config
- echo " IdentityFile ~/.ssh/gitlab-ci" >> .ssh/config
- git config --global url.ssh://git@code.fbi.h-da.de/.insteadOf https://code.fbi.h-da.de/
Build:
stage: build
script:
- go mod init code.fbi.h-da.de/cocsn/cocsn-api
- swagger generate server -A cocsn -f ./cocsn-v0.0.1.yml
- git push origin HEAD:$CI_COMMIT_REF_NAME
\ No newline at end of file
// Code generated by go-swagger; DO NOT EDIT.
package main
import (
"log"
"os"
"code.fbi.h-da.de/cocsn/cocsn-api/restapi"
"code.fbi.h-da.de/cocsn/cocsn-api/restapi/operations"
"github.com/go-openapi/loads"
flags "github.com/jessevdk/go-flags"
)
// This file was generated by the swagger tool.
// Make sure not to overwrite this file after you generated it because all your edits would be lost!
func main() {
swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
if err != nil {
log.Fatalln(err)
}
api := operations.NewCocsnAPI(swaggerSpec)
server := restapi.NewServer(api)
defer server.Shutdown()
parser := flags.NewParser(server, flags.Default)
parser.ShortDescription = "CoCSN"
parser.LongDescription = "Simple RESTCONF API"
server.ConfigureFlags()
for _, optsGroup := range api.CommandLineOptionsGroups {
_, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options)
if err != nil {
log.Fatalln(err)
}
}
if _, err := parser.Parse(); err != nil {
code := 1
if fe, ok := err.(*flags.Error); ok {
if fe.Type == flags.ErrHelp {
code = 0
}
}
os.Exit(code)
}
server.ConfigureAPI()
if err := server.Serve(); err != nil {
log.Fatalln(err)
}
}
swagger: '2.0'
info:
version: '0.0.1'
title: CoCSN
description: Simple RESTCONF API
contact:
name: Your name
basePath: /restconf
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/data/cocsn-interfaces:
get:
summary: 'Returns a list of interfaces'
operationId: getInterfaces
tags:
- interface
produces:
- application/json
responses:
200:
description: OK
schema:
$ref: '#/definitions/Interfaces'
404:
description: An error occurred.
default:
description: Unexpected error
/data/cocsn-interface/{interface}/ip-addresses:
get:
summary: 'Returns IP addresses of an interface'
operationId: getIPAddresses
parameters:
- in: path
name: interface
description: interface to fetch
required: true
type: string
tags:
- interface
produces:
- application/json
responses:
200:
description: OK
schema:
$ref: '#/definitions/LogicalAddresses'
404:
description: An error occurred.
default:
description: Unexpected error
/data/cocsn-interface/{interface}/mac-address:
get:
summary: 'Returns MAC address of an interface'
operationId: getMACAddress
parameters:
- in: path
name: interface
description: interface to fetch
required: true
type: string
tags:
- interface
produces:
- application/json
responses:
200:
description: OK
schema:
$ref: '#/definitions/PhysicalAddress'
404:
description: An error occurred.
default:
description: Unexpected error
definitions:
Interfaces:
type: array
items:
type: string
properties:
name:
type: string
PhysicalAddress:
type: string
properties:
name:
type: string
LogicalAddresses:
type: array
items:
type: string
properties:
name:
type: string
\ No newline at end of file
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
)
// Interface interface
//
// swagger:model Interface
type Interface []string
// Validate validates this interface
func (m Interface) Validate(formats strfmt.Registry) error {
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
)
// Interfaces interfaces
//
// swagger:model Interfaces
type Interfaces []string
// Validate validates this interfaces
func (m Interfaces) Validate(formats strfmt.Registry) error {
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
)
// LogicalAddresses logical addresses
//
// swagger:model LogicalAddresses
type LogicalAddresses []string
// Validate validates this logical addresses
func (m LogicalAddresses) Validate(formats strfmt.Registry) error {
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
)
// PhysicalAddress physical address
//
// swagger:model PhysicalAddress
type PhysicalAddress string
// Validate validates this physical address
func (m PhysicalAddress) Validate(formats strfmt.Registry) error {
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// This file is safe to edit. Once it exists it will not be overwritten
package restapi
import (
"crypto/tls"
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"code.fbi.h-da.de/cocsn/cocsn-api/api/restapi/operations"
"code.fbi.h-da.de/cocsn/cocsn-api/api/restapi/operations/interface_operations"
)
//go:generate swagger generate server --target ../../generated --name Cocsn --spec ../../cocsn-v0.0.1.yml --principal interface{}
func configureFlags(api *operations.CocsnAPI) {
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
}
func configureAPI(api *operations.CocsnAPI) http.Handler {
// configure the api here
api.ServeError = errors.ServeError
// Set your custom logger if needed. Default one is log.Printf
// Expected interface func(string, ...interface{})
//
// Example:
// api.Logger = log.Printf
api.UseSwaggerUI()
// To continue using redoc as your UI, uncomment the following line
// api.UseRedoc()
api.JSONConsumer = runtime.JSONConsumer()
api.JSONProducer = runtime.JSONProducer()
if api.InterfaceOperationsGetInterfacesHandler == nil {
api.InterfaceOperationsGetInterfacesHandler = interface_operations.GetInterfacesHandlerFunc(func(params interface_operations.GetInterfacesParams) middleware.Responder {
return middleware.NotImplemented("operation interface_operations.GetInterfaces has not yet been implemented")
})
}
api.PreServerShutdown = func() {}
api.ServerShutdown = func() {}
return setupGlobalMiddleware(api.Serve(setupMiddlewares))
}
// The TLS configuration before HTTPS server starts.
func configureTLS(tlsConfig *tls.Config) {
// Make all necessary changes to the TLS configuration here.
}
// As soon as server is initialized but not run yet, this function will be called.
// If you need to modify a config, store server instance to stop it individually later, this is the place.
// This function can be called multiple times, depending on the number of serving schemes.
// scheme value will be set accordingly: "http", "https" or "unix"
func configureServer(s *http.Server, scheme, addr string) {
}
// The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
// The middleware executes after routing but before authentication, binding and validation
func setupMiddlewares(handler http.Handler) http.Handler {
return handler
}
// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
// So this is a good place to plug in a panic handling middleware, logging and metrics
func setupGlobalMiddleware(handler http.Handler) http.Handler {
return handler
}
// Code generated by go-swagger; DO NOT EDIT.
// Package restapi CoCSN
//
// Simple RESTCONF API
// Schemes:
// http
// Host: localhost
// BasePath: /restconf
// Version: 0.0.1
// Contact: Your name
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package restapi
// Code generated by go-swagger; DO NOT EDIT.
package restapi
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
)
var (
// SwaggerJSON embedded version of the swagger document used at generation time
SwaggerJSON json.RawMessage
// FlatSwaggerJSON embedded flattened version of the swagger document used at generation time
FlatSwaggerJSON json.RawMessage
)
func init() {
SwaggerJSON = json.RawMessage([]byte(`{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http"
],
"swagger": "2.0",
"info": {
"description": "Simple RESTCONF API",
"title": "CoCSN",
"contact": {
"name": "Your name"
},
"version": "0.0.1"
},
"basePath": "/restconf",
"paths": {
"/data/cocsn-interface/{interface}/ip-addresses": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns IP addresses of an interface",
"operationId": "getIPAddresses",
"parameters": [
{
"type": "string",
"description": "interface to fetch",
"name": "interface",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/LogicalAddresses"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
},
"/data/cocsn-interface/{interface}/mac-address": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns MAC address of an interface",
"operationId": "getMACAddress",
"parameters": [
{
"type": "string",
"description": "interface to fetch",
"name": "interface",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/PhysicalAddress"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
},
"/data/cocsn-interfaces": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns a list of interfaces",
"operationId": "getInterfaces",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Interfaces"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
}
},
"definitions": {
"Interfaces": {
"type": "array",
"items": {
"type": "string"
},
"properties": {
"name": {
"type": "string"
}
}
},
"LogicalAddresses": {
"type": "array",
"items": {
"type": "string"
},
"properties": {
"name": {
"type": "string"
}
}
},
"PhysicalAddress": {
"type": "string",
"properties": {
"name": {
"type": "string"
}
}
}
}
}`))
FlatSwaggerJSON = json.RawMessage([]byte(`{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http"
],
"swagger": "2.0",
"info": {
"description": "Simple RESTCONF API",
"title": "CoCSN",
"contact": {
"name": "Your name"
},
"version": "0.0.1"
},
"basePath": "/restconf",
"paths": {
"/data/cocsn-interface/{interface}/ip-addresses": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns IP addresses of an interface",
"operationId": "getIPAddresses",
"parameters": [
{
"type": "string",
"description": "interface to fetch",
"name": "interface",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/LogicalAddresses"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
},
"/data/cocsn-interface/{interface}/mac-address": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns MAC address of an interface",
"operationId": "getMACAddress",
"parameters": [
{
"type": "string",
"description": "interface to fetch",
"name": "interface",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/PhysicalAddress"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
},
"/data/cocsn-interfaces": {
"get": {
"produces": [
"application/json"
],
"tags": [
"interface"
],
"summary": "Returns a list of interfaces",
"operationId": "getInterfaces",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Interfaces"
}
},
"404": {
"description": "An error occurred."
},
"default": {
"description": "Unexpected error"
}
}
}
}
},
"definitions": {
"Interfaces": {
"type": "array",
"items": {
"type": "string"
},
"properties": {
"name": {
"type": "string"
}
}
},
"LogicalAddresses": {
"type": "array",
"items": {
"type": "string"
},
"properties": {
"name": {
"type": "string"
}
}
},
"PhysicalAddress": {
"type": "string",
"properties": {
"name": {
"type": "string"
}
}
}
}
}`))
}
// Code generated by go-swagger; DO NOT EDIT.
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"
"github.com/go-openapi/errors"
"github.com/go-openapi/loads"
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/runtime/security"
"github.com/go-openapi/spec"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"code.fbi.h-da.de/cocsn/cocsn-api/restapi/operations/interface_operations"
)
// NewCocsnAPI creates a new Cocsn instance
func NewCocsnAPI(spec *loads.Document) *CocsnAPI {
return &CocsnAPI{
handlers: make(map[string]map[string]http.Handler),
formats: strfmt.Default,
defaultConsumes: "application/json",
defaultProduces: "application/json",
customConsumers: make(map[string]runtime.Consumer),
customProducers: make(map[string]runtime.Producer),
PreServerShutdown: func() {},
ServerShutdown: func() {},
spec: spec,
useSwaggerUI: false,
ServeError: errors.ServeError,
BasicAuthenticator: security.BasicAuth,
APIKeyAuthenticator: security.APIKeyAuth,
BearerAuthenticator: security.BearerAuth,
JSONConsumer: runtime.JSONConsumer(),
JSONProducer: runtime.JSONProducer(),
InterfaceOperationsGetIPAddressesHandler: interface_operations.GetIPAddressesHandlerFunc(func(params interface_operations.GetIPAddressesParams) middleware.Responder {
return middleware.NotImplemented("operation interface_operations.GetIPAddresses has not yet been implemented")
}),
InterfaceOperationsGetInterfacesHandler: interface_operations.GetInterfacesHandlerFunc(func(params interface_operations.GetInterfacesParams) middleware.Responder {
return middleware.NotImplemented("operation interface_operations.GetInterfaces has not yet been implemented")
}),
InterfaceOperationsGetMACAddressHandler: interface_operations.GetMACAddressHandlerFunc(func(params interface_operations.GetMACAddressParams) middleware.Responder {
return middleware.NotImplemented("operation interface_operations.GetMACAddress has not yet been implemented")
}),
}
}
/*CocsnAPI Simple RESTCONF API */
type CocsnAPI struct {
spec *loads.Document
context *middleware.Context
handlers map[string]map[string]http.Handler
formats strfmt.Registry
customConsumers map[string]runtime.Consumer
customProducers map[string]runtime.Producer
defaultConsumes string
defaultProduces string
Middleware func(middleware.Builder) http.Handler
useSwaggerUI bool
// BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
// It has a default implementation in the security package, however you can replace it for your particular usage.
BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
// APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
// It has a default implementation in the security package, however you can replace it for your particular usage.
APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
// BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
// It has a default implementation in the security package, however you can replace it for your particular usage.
BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
// JSONConsumer registers a consumer for the following mime types:
// - application/json
JSONConsumer runtime.Consumer
// JSONProducer registers a producer for the following mime types:
// - application/json
JSONProducer runtime.Producer
// InterfaceOperationsGetIPAddressesHandler sets the operation handler for the get IP addresses operation
InterfaceOperationsGetIPAddressesHandler interface_operations.GetIPAddressesHandler
// InterfaceOperationsGetInterfacesHandler sets the operation handler for the get interfaces operation
InterfaceOperationsGetInterfacesHandler interface_operations.GetInterfacesHandler
// InterfaceOperationsGetMACAddressHandler sets the operation handler for the get m a c address operation
InterfaceOperationsGetMACAddressHandler interface_operations.GetMACAddressHandler
// 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)
// PreServerShutdown is called before the HTTP(S) server is shutdown
// This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
PreServerShutdown func()
// 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{})
}
// UseRedoc for documentation at /docs
func (o *CocsnAPI) UseRedoc() {
o.useSwaggerUI = false
}
// UseSwaggerUI for documentation at /docs
func (o *CocsnAPI) UseSwaggerUI() {
o.useSwaggerUI = true
}
// SetDefaultProduces sets the default produces media type
func (o *CocsnAPI) SetDefaultProduces(mediaType string) {
o.defaultProduces = mediaType
}
// SetDefaultConsumes returns the default consumes media type
func (o *CocsnAPI) SetDefaultConsumes(mediaType string) {
o.defaultConsumes = mediaType
}
// SetSpec sets a spec that will be served for the clients.
func (o *CocsnAPI) SetSpec(spec *loads.Document) {
o.spec = spec
}
// DefaultProduces returns the default produces media type
func (o *CocsnAPI) DefaultProduces() string {
return o.defaultProduces
}
// DefaultConsumes returns the default consumes media type
func (o *CocsnAPI) DefaultConsumes() string {
return o.defaultConsumes
}
// Formats returns the registered string formats
func (o *CocsnAPI) Formats() strfmt.Registry {
return o.formats
}
// RegisterFormat registers a custom format validator
func (o *CocsnAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
o.formats.Add(name, format, validator)
}
// Validate validates the registrations in the CocsnAPI
func (o *CocsnAPI) Validate() error {
var unregistered []string
if o.JSONConsumer == nil {
unregistered = append(unregistered, "JSONConsumer")
}
if o.JSONProducer == nil {
unregistered = append(unregistered, "JSONProducer")
}
if o.InterfaceOperationsGetIPAddressesHandler == nil {
unregistered = append(unregistered, "interface_operations.GetIPAddressesHandler")
}
if o.InterfaceOperationsGetInterfacesHandler == nil {
unregistered = append(unregistered, "interface_operations.GetInterfacesHandler")
}
if o.InterfaceOperationsGetMACAddressHandler == nil {
unregistered = append(unregistered, "interface_operations.GetMACAddressHandler")
}
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 *CocsnAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
return o.ServeError
}
// AuthenticatorsFor gets the authenticators for the specified security schemes
func (o *CocsnAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
return nil
}
// Authorizer returns the registered authorizer
func (o *CocsnAPI) Authorizer() runtime.Authorizer {
return nil
}
// ConsumersFor gets the consumers for the specified media types.
// MIME type parameters are ignored here.
func (o *CocsnAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
result := make(map[string]runtime.Consumer, len(mediaTypes))
for _, mt := range mediaTypes {
switch mt {
case "application/json":
result["application/json"] = o.JSONConsumer
}
if c, ok := o.customConsumers[mt]; ok {
result[mt] = c
}
}
return result
}
// ProducersFor gets the producers for the specified media types.
// MIME type parameters are ignored here.
func (o *CocsnAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
result := make(map[string]runtime.Producer, len(mediaTypes))
for _, mt := range mediaTypes {
switch mt {
case "application/json":
result["application/json"] = o.JSONProducer
}
if p, ok := o.customProducers[mt]; ok {
result[mt] = p
}
}
return result
}
// HandlerFor gets a http.Handler for the provided operation method and path
func (o *CocsnAPI) 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
}
if path == "/" {
path = ""
}
h, ok := o.handlers[um][path]
return h, ok
}
// Context returns the middleware context for the cocsn API
func (o *CocsnAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
}
func (o *CocsnAPI) 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["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/data/cocsn-interface/{interface}/ip-addresses"] = interface_operations.NewGetIPAddresses(o.context, o.InterfaceOperationsGetIPAddressesHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/data/cocsn-interfaces"] = interface_operations.NewGetInterfaces(o.context, o.InterfaceOperationsGetInterfacesHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/data/cocsn-interface/{interface}/mac-address"] = interface_operations.NewGetMACAddress(o.context, o.InterfaceOperationsGetMACAddressHandler)
}
// Serve creates a http handler to serve the API over HTTP
// can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
func (o *CocsnAPI) Serve(builder middleware.Builder) http.Handler {
o.Init()
if o.Middleware != nil {
return o.Middleware(builder)
}
if o.useSwaggerUI {
return o.context.APIHandlerSwaggerUI(builder)
}
return o.context.APIHandler(builder)
}
// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
func (o *CocsnAPI) Init() {
if len(o.handlers) == 0 {
o.initHandlerCache()
}
}
// RegisterConsumer allows you to add (or override) a consumer for a media type.
func (o *CocsnAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
o.customConsumers[mediaType] = consumer
}
// RegisterProducer allows you to add (or override) a producer for a media type.
func (o *CocsnAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
o.customProducers[mediaType] = producer
}
// AddMiddlewareFor adds a http middleware to existing handler
func (o *CocsnAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
um := strings.ToUpper(method)
if path == "/" {
path = ""
}
o.Init()
if h, ok := o.handlers[um][path]; ok {
o.handlers[method][path] = builder(h)
}
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
)
// GetHWAddressesHandlerFunc turns a function with the right signature into a get h w addresses handler
type GetHWAddressesHandlerFunc func(GetHWAddressesParams) middleware.Responder
// Handle executing the request and returning a response
func (fn GetHWAddressesHandlerFunc) Handle(params GetHWAddressesParams) middleware.Responder {
return fn(params)
}
// GetHWAddressesHandler interface for that can handle valid get h w addresses params
type GetHWAddressesHandler interface {
Handle(GetHWAddressesParams) middleware.Responder
}
// NewGetHWAddresses creates a new http.Handler for the get h w addresses operation
func NewGetHWAddresses(ctx *middleware.Context, handler GetHWAddressesHandler) *GetHWAddresses {
return &GetHWAddresses{Context: ctx, Handler: handler}
}
/*GetHWAddresses swagger:route GET /data/cocsn-interface/{interface}/mac-address interface getHWAddresses
Returns harware address of an interface
*/
type GetHWAddresses struct {
Context *middleware.Context
Handler GetHWAddressesHandler
}
func (o *GetHWAddresses) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewGetHWAddressesParams()
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
)
// NewGetHWAddressesParams creates a new GetHWAddressesParams object
// no default values defined in spec.
func NewGetHWAddressesParams() GetHWAddressesParams {
return GetHWAddressesParams{}
}
// GetHWAddressesParams contains all the bound params for the get h w addresses operation
// typically these are obtained from a http.Request
//
// swagger:parameters getHWAddresses
type GetHWAddressesParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*interface to fetch
Required: true
In: path
*/
Interface string
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewGetHWAddressesParams() beforehand.
func (o *GetHWAddressesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
rInterface, rhkInterface, _ := route.Params.GetOK("interface")
if err := o.bindInterface(rInterface, rhkInterface, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindInterface binds and validates parameter Interface from path.
func (o *GetHWAddressesParams) bindInterface(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.Interface = raw
return nil
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"code.fbi.h-da.de/cocsn/cocsn-api/api/models"
)
// GetHWAddressesOKCode is the HTTP code returned for type GetHWAddressesOK
const GetHWAddressesOKCode int = 200
/*GetHWAddressesOK OK
swagger:response getHWAddressesOK
*/
type GetHWAddressesOK struct {
/*
In: Body
*/
Payload models.PhysicalAddress `json:"body,omitempty"`
}
// NewGetHWAddressesOK creates GetHWAddressesOK with default headers values
func NewGetHWAddressesOK() *GetHWAddressesOK {
return &GetHWAddressesOK{}
}
// WithPayload adds the payload to the get h w addresses o k response
func (o *GetHWAddressesOK) WithPayload(payload models.PhysicalAddress) *GetHWAddressesOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get h w addresses o k response
func (o *GetHWAddressesOK) SetPayload(payload models.PhysicalAddress) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetHWAddressesOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
// GetHWAddressesNotFoundCode is the HTTP code returned for type GetHWAddressesNotFound
const GetHWAddressesNotFoundCode int = 404
/*GetHWAddressesNotFound An error occurred.
swagger:response getHWAddressesNotFound
*/
type GetHWAddressesNotFound struct {
}
// NewGetHWAddressesNotFound creates GetHWAddressesNotFound with default headers values
func NewGetHWAddressesNotFound() *GetHWAddressesNotFound {
return &GetHWAddressesNotFound{}
}
// WriteResponse to the client
func (o *GetHWAddressesNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(404)
}
/*GetHWAddressesDefault Unexpected error
swagger:response getHWAddressesDefault
*/
type GetHWAddressesDefault struct {
_statusCode int
}
// NewGetHWAddressesDefault creates GetHWAddressesDefault with default headers values
func NewGetHWAddressesDefault(code int) *GetHWAddressesDefault {
if code <= 0 {
code = 500
}
return &GetHWAddressesDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get h w addresses default response
func (o *GetHWAddressesDefault) WithStatusCode(code int) *GetHWAddressesDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get h w addresses default response
func (o *GetHWAddressesDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WriteResponse to the client
func (o *GetHWAddressesDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(o._statusCode)
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
"strings"
)
// GetHWAddressesURL generates an URL for the get h w addresses operation
type GetHWAddressesURL struct {
Interface string
_basePath string
// avoid unkeyed usage
_ struct{}
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *GetHWAddressesURL) WithBasePath(bp string) *GetHWAddressesURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *GetHWAddressesURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetHWAddressesURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/data/cocsn-interface/{interface}/mac-address"
interfaceVar := o.Interface
if interfaceVar != "" {
_path = strings.Replace(_path, "{interface}", interfaceVar, -1)
} else {
return nil, errors.New("interface is required on GetHWAddressesURL")
}
_basePath := o._basePath
if _basePath == "" {
_basePath = "/restconf"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *GetHWAddressesURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *GetHWAddressesURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetHWAddressesURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetHWAddressesURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetHWAddressesURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *GetHWAddressesURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
)
// GetInterfacesHandlerFunc turns a function with the right signature into a get interfaces handler
type GetInterfacesHandlerFunc func(GetInterfacesParams) middleware.Responder
// Handle executing the request and returning a response
func (fn GetInterfacesHandlerFunc) Handle(params GetInterfacesParams) middleware.Responder {
return fn(params)
}
// GetInterfacesHandler interface for that can handle valid get interfaces params
type GetInterfacesHandler interface {
Handle(GetInterfacesParams) middleware.Responder
}
// NewGetInterfaces creates a new http.Handler for the get interfaces operation
func NewGetInterfaces(ctx *middleware.Context, handler GetInterfacesHandler) *GetInterfaces {
return &GetInterfaces{Context: ctx, Handler: handler}
}
/*GetInterfaces swagger:route GET /data/cocsn-interfaces interface getInterfaces
Returns a list of interfaces
*/
type GetInterfaces struct {
Context *middleware.Context
Handler GetInterfacesHandler
}
func (o *GetInterfaces) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewGetInterfacesParams()
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime/middleware"
)
// NewGetInterfacesParams creates a new GetInterfacesParams object
// no default values defined in spec.
func NewGetInterfacesParams() GetInterfacesParams {
return GetInterfacesParams{}
}
// GetInterfacesParams contains all the bound params for the get interfaces operation
// typically these are obtained from a http.Request
//
// swagger:parameters getInterfaces
type GetInterfacesParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewGetInterfacesParams() beforehand.
func (o *GetInterfacesParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"code.fbi.h-da.de/cocsn/cocsn-api/models"
)
// GetInterfacesOKCode is the HTTP code returned for type GetInterfacesOK
const GetInterfacesOKCode int = 200
/*GetInterfacesOK OK
swagger:response getInterfacesOK
*/
type GetInterfacesOK struct {
/*
In: Body
*/
Payload models.Interfaces `json:"body,omitempty"`
}
// NewGetInterfacesOK creates GetInterfacesOK with default headers values
func NewGetInterfacesOK() *GetInterfacesOK {
return &GetInterfacesOK{}
}
// WithPayload adds the payload to the get interfaces o k response
func (o *GetInterfacesOK) WithPayload(payload models.Interfaces) *GetInterfacesOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the get interfaces o k response
func (o *GetInterfacesOK) SetPayload(payload models.Interfaces) {
o.Payload = payload
}
// WriteResponse to the client
func (o *GetInterfacesOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
payload := o.Payload
if payload == nil {
// return empty array
payload = models.Interfaces{}
}
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
// GetInterfacesNotFoundCode is the HTTP code returned for type GetInterfacesNotFound
const GetInterfacesNotFoundCode int = 404
/*GetInterfacesNotFound An error occurred.
swagger:response getInterfacesNotFound
*/
type GetInterfacesNotFound struct {
}
// NewGetInterfacesNotFound creates GetInterfacesNotFound with default headers values
func NewGetInterfacesNotFound() *GetInterfacesNotFound {
return &GetInterfacesNotFound{}
}
// WriteResponse to the client
func (o *GetInterfacesNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(404)
}
/*GetInterfacesDefault Unexpected error
swagger:response getInterfacesDefault
*/
type GetInterfacesDefault struct {
_statusCode int
}
// NewGetInterfacesDefault creates GetInterfacesDefault with default headers values
func NewGetInterfacesDefault(code int) *GetInterfacesDefault {
if code <= 0 {
code = 500
}
return &GetInterfacesDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the get interfaces default response
func (o *GetInterfacesDefault) WithStatusCode(code int) *GetInterfacesDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the get interfaces default response
func (o *GetInterfacesDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WriteResponse to the client
func (o *GetInterfacesDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
rw.WriteHeader(o._statusCode)
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
)
// GetInterfacesURL generates an URL for the get interfaces operation
type GetInterfacesURL struct {
_basePath string
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *GetInterfacesURL) WithBasePath(bp string) *GetInterfacesURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *GetInterfacesURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *GetInterfacesURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/data/cocsn-interfaces"
_basePath := o._basePath
if _basePath == "" {
_basePath = "/restconf"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *GetInterfacesURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *GetInterfacesURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *GetInterfacesURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on GetInterfacesURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on GetInterfacesURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *GetInterfacesURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}
// Code generated by go-swagger; DO NOT EDIT.
package interface_operations
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
)
// GetIPAddressesHandlerFunc turns a function with the right signature into a get IP addresses handler
type GetIPAddressesHandlerFunc func(GetIPAddressesParams) middleware.Responder
// Handle executing the request and returning a response
func (fn GetIPAddressesHandlerFunc) Handle(params GetIPAddressesParams) middleware.Responder {
return fn(params)
}
// GetIPAddressesHandler interface for that can handle valid get IP addresses params
type GetIPAddressesHandler interface {
Handle(GetIPAddressesParams) middleware.Responder
}
// NewGetIPAddresses creates a new http.Handler for the get IP addresses operation
func NewGetIPAddresses(ctx *middleware.Context, handler GetIPAddressesHandler) *GetIPAddresses {
return &GetIPAddresses{Context: ctx, Handler: handler}
}
/*GetIPAddresses swagger:route GET /data/cocsn-interface/{interface}/ip-addresses interface getIpAddresses
Returns IP addresses of an interface
*/
type GetIPAddresses struct {
Context *middleware.Context
Handler GetIPAddressesHandler
}
func (o *GetIPAddresses) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewGetIPAddressesParams()
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment