openapi

package
v0.0.0-...-d3ca18a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeAssertionError is thrown when type an interface does not match the asserted type
	ErrTypeAssertionError = errors.New("unable to assert type")
)

Functions

func AssertRecurseInterfaceRequired

func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error

AssertInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertRecurseServiceStatusRequired

func AssertRecurseServiceStatusRequired(objSlice interface{}) error

AssertRecurseServiceStatusRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of ServiceStatus (e.g. [][]ServiceStatus), otherwise ErrTypeAssertionError is thrown.

func AssertRecurseValueRequired

func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error

AssertNestedValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertRecurseWakeStatusRequired

func AssertRecurseWakeStatusRequired(objSlice interface{}) error

AssertRecurseWakeStatusRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of WakeStatus (e.g. [][]WakeStatus), otherwise ErrTypeAssertionError is thrown.

func AssertServiceStatusRequired

func AssertServiceStatusRequired(obj ServiceStatus) error

AssertServiceStatusRequired checks if the required fields are not zero-ed

func AssertWakeStatusRequired

func AssertWakeStatusRequired(obj WakeStatus) error

AssertWakeStatusRequired checks if the required fields are not zero-ed

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

DefaultErrorHandler defines the default logic on how to handle errors from the controller. Any errors from parsing request params will return a StatusBadRequest. Otherwise, the error code originating from the servicer will be used.

func EncodeJSONResponse

func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error

EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code

func IsZeroValue

func IsZeroValue(val interface{}) bool

IsZeroValue checks if the val is the zero-ed value.

func Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter(routers ...Router) chi.Router

NewRouter creates a new router for any number of api routers

func ReadFormFileToTempFile

func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)

ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file

func ReadFormFilesToTempFiles

func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)

ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files

Types

type DefaultApiController

type DefaultApiController struct {
	// contains filtered or unexported fields
}

DefaultApiController binds http requests to an api service and writes the service results to the http response

func (*DefaultApiController) HealthGet

func (c *DefaultApiController) HealthGet(w http.ResponseWriter, r *http.Request)

HealthGet -

func (*DefaultApiController) HealthServicePost

func (c *DefaultApiController) HealthServicePost(w http.ResponseWriter, r *http.Request)

HealthServicePost -

func (*DefaultApiController) Routes

func (c *DefaultApiController) Routes() Routes

Routes returns all of the api route for the DefaultApiController

func (*DefaultApiController) WakeGet

WakeGet -

func (*DefaultApiController) WakePost

WakePost -

type DefaultApiOption

type DefaultApiOption func(*DefaultApiController)

DefaultApiOption for how the controller is set up.

func WithDefaultApiErrorHandler

func WithDefaultApiErrorHandler(h ErrorHandler) DefaultApiOption

WithDefaultApiErrorHandler inject ErrorHandler into controller

type DefaultApiRouter

type DefaultApiRouter interface {
	HealthGet(http.ResponseWriter, *http.Request)
	HealthServicePost(http.ResponseWriter, *http.Request)
	WakeGet(http.ResponseWriter, *http.Request)
	WakePost(http.ResponseWriter, *http.Request)
}

DefaultApiRouter defines the required methods for binding the api requests to a responses for the DefaultApi The DefaultApiRouter implementation should parse necessary information from the http request, pass the data to a DefaultApiServicer to perform the required actions, then write the service results to the http response.

type DefaultApiServicer

type DefaultApiServicer interface {
	HealthGet(context.Context) (ImplResponse, error)
	HealthServicePost(context.Context, string) (ImplResponse, error)
	WakeGet(context.Context) (ImplResponse, error)
	WakePost(context.Context) (ImplResponse, error)
}

DefaultApiServicer defines the api actions for the DefaultApi service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

ErrorHandler defines the required method for handling error. You may implement it and inject this into a controller if you would like errors to be handled differently from the DefaultErrorHandler

type ImplResponse

type ImplResponse struct {
	Code int
	Body interface{}
}

Implementation response defines an error code with the associated body

func Response

func Response(code int, body interface{}) ImplResponse

Response return a ImplResponse struct filled

type ParsingError

type ParsingError struct {
	Err error
}

ParsingError indicates that an error has occurred when parsing request parameters

func (*ParsingError) Error

func (e *ParsingError) Error() string

func (*ParsingError) Unwrap

func (e *ParsingError) Unwrap() error

type RequiredError

type RequiredError struct {
	Field string
}

RequiredError indicates that an error has occurred when parsing request parameters

func (*RequiredError) Error

func (e *RequiredError) Error() string

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route defines the parameters for an api endpoint

type Router

type Router interface {
	Routes() Routes
}

Router defines the required methods for retrieving api routes

func NewDefaultApiController

func NewDefaultApiController(s DefaultApiServicer, opts ...DefaultApiOption) Router

NewDefaultApiController creates a default api controller

type Routes

type Routes []Route

Routes are a collection of defined api endpoints

type ServiceStatus

type ServiceStatus struct {
	Service string `json:"service"`

	UpdatedAt string `json:"updatedAt"`
}

type WakeStatus

type WakeStatus struct {
	WakeDevice bool `json:"wake_device"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL