Documentation ¶
Index ¶
- Variables
- func AssertEventRequired(obj Event) error
- func AssertRecurseEventRequired(objSlice interface{}) error
- func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error
- func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)
- func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error
- func IsZeroValue(val interface{}) bool
- func Logger(inner http.Handler, name string) http.Handler
- func NewRouter(routers ...Router) chi.Router
- func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)
- func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)
- type ErrorHandler
- type Event
- type EventsApiController
- type EventsApiOption
- type EventsApiRouter
- type EventsApiService
- type EventsApiServicer
- type ImplResponse
- type ParsingError
- type RequiredError
- type Route
- type Router
- type Routes
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTypeAssertionError is thrown when type an interface does not match the asserted type ErrTypeAssertionError = errors.New("unable to assert type") )
Functions ¶
func AssertEventRequired ¶
AssertEventRequired checks if the required fields are not zero-ed
func AssertRecurseEventRequired ¶
func AssertRecurseEventRequired(objSlice interface{}) error
AssertRecurseEventRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of Event (e.g. [][]Event), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseInterfaceRequired ¶
AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired ¶
AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion.
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 NewRouter ¶
func NewRouter(routers ...Router) chi.Router
NewRouter creates a new router for any number of api routers
func ReadFormFileToTempFile ¶
ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
Types ¶
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 EventsApiController ¶
type EventsApiController struct {
// contains filtered or unexported fields
}
EventsApiController binds http requests to an api service and writes the service results to the http response
func (*EventsApiController) EventsGet ¶
func (c *EventsApiController) EventsGet(w http.ResponseWriter, r *http.Request)
EventsGet - Get all events.
func (*EventsApiController) EventsPost ¶
func (c *EventsApiController) EventsPost(w http.ResponseWriter, r *http.Request)
EventsPost - Create event.
func (*EventsApiController) Routes ¶
func (c *EventsApiController) Routes() Routes
Routes returns all the api routes for the EventsApiController
type EventsApiOption ¶
type EventsApiOption func(*EventsApiController)
EventsApiOption for how the controller is set up.
func WithEventsApiErrorHandler ¶
func WithEventsApiErrorHandler(h ErrorHandler) EventsApiOption
WithEventsApiErrorHandler inject ErrorHandler into controller
type EventsApiRouter ¶
type EventsApiRouter interface { EventsGet(http.ResponseWriter, *http.Request) EventsPost(http.ResponseWriter, *http.Request) }
EventsApiRouter defines the required methods for binding the api requests to a responses for the EventsApi The EventsApiRouter implementation should parse necessary information from the http request, pass the data to a EventsApiServicer to perform the required actions, then write the service results to the http response.
type EventsApiService ¶
type EventsApiService struct { }
EventsApiService is a service that implements the logic for the EventsApiServicer This service should implement the business logic for every endpoint for the EventsApi API. Include any external packages or services that will be required by this service.
func (*EventsApiService) EventsGet ¶
func (s *EventsApiService) EventsGet(ctx context.Context) (ImplResponse, error)
EventsGet - Get all events.
func (*EventsApiService) EventsPost ¶
func (s *EventsApiService) EventsPost(ctx context.Context, event Event) (ImplResponse, error)
EventsPost - Create event.
type EventsApiServicer ¶
type EventsApiServicer interface { EventsGet(context.Context) (ImplResponse, error) EventsPost(context.Context, Event) (ImplResponse, error) }
EventsApiServicer defines the api actions for the EventsApi service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.
func NewEventsApiService ¶
func NewEventsApiService() EventsApiServicer
NewEventsApiService creates a default api service
type ImplResponse ¶
type ImplResponse struct { Code int Body interface{} }
ImplResponse 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 NewEventsApiController ¶
func NewEventsApiController(s EventsApiServicer, opts ...EventsApiOption) Router
NewEventsApiController creates a default api controller