Documentation ¶
Index ¶
- Variables
- func AssertAddTodoItemRequestRequired(obj AddTodoItemRequest) error
- func AssertErrorRequired(obj Error) error
- func AssertRecurseAddTodoItemRequestRequired(objSlice interface{}) error
- func AssertRecurseErrorRequired(objSlice interface{}) error
- func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error
- func AssertRecurseTodoItemRequired(objSlice interface{}) error
- func AssertRecurseUpdateTodoItemRequestRequired(objSlice interface{}) error
- func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error
- func AssertTodoItemRequired(obj TodoItem) error
- func AssertUpdateTodoItemRequestRequired(obj UpdateTodoItemRequest) 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 AddTodoItemRequest
- type Error
- type ErrorHandler
- type ImplResponse
- type ParsingError
- type RequiredError
- type Route
- type Router
- type Routes
- type TodoItem
- type TodoListApiController
- func (c *TodoListApiController) AddItem(w http.ResponseWriter, r *http.Request)
- func (c *TodoListApiController) DeleteItem(w http.ResponseWriter, r *http.Request)
- func (c *TodoListApiController) DeleteItems(w http.ResponseWriter, r *http.Request)
- func (c *TodoListApiController) GetItem(w http.ResponseWriter, r *http.Request)
- func (c *TodoListApiController) ListItems(w http.ResponseWriter, r *http.Request)
- func (c *TodoListApiController) Routes() Routes
- func (c *TodoListApiController) UpdateItem(w http.ResponseWriter, r *http.Request)
- type TodoListApiOption
- type TodoListApiRouter
- type TodoListApiServicer
- type UpdateTodoItemRequest
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 AssertAddTodoItemRequestRequired ¶
func AssertAddTodoItemRequestRequired(obj AddTodoItemRequest) error
AssertAddTodoItemRequestRequired checks if the required fields are not zero-ed
func AssertErrorRequired ¶
AssertErrorRequired checks if the required fields are not zero-ed
func AssertRecurseAddTodoItemRequestRequired ¶
func AssertRecurseAddTodoItemRequestRequired(objSlice interface{}) error
AssertRecurseAddTodoItemRequestRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of AddTodoItemRequest (e.g. [][]AddTodoItemRequest), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseErrorRequired ¶
func AssertRecurseErrorRequired(objSlice interface{}) error
AssertRecurseErrorRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of Error (e.g. [][]Error), 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 AssertRecurseTodoItemRequired ¶
func AssertRecurseTodoItemRequired(objSlice interface{}) error
AssertRecurseTodoItemRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of TodoItem (e.g. [][]TodoItem), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseUpdateTodoItemRequestRequired ¶
func AssertRecurseUpdateTodoItemRequestRequired(objSlice interface{}) error
AssertRecurseUpdateTodoItemRequestRequired recursively checks if required fields are not zero-ed in a nested slice. Accepts only nested slice of UpdateTodoItemRequest (e.g. [][]UpdateTodoItemRequest), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseValueRequired ¶
AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion.
func AssertTodoItemRequired ¶
AssertTodoItemRequired checks if the required fields are not zero-ed
func AssertUpdateTodoItemRequestRequired ¶
func AssertUpdateTodoItemRequestRequired(obj UpdateTodoItemRequest) error
AssertUpdateTodoItemRequestRequired 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 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 AddTodoItemRequest ¶
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{} }
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 NewTodoListApiController ¶
func NewTodoListApiController(s TodoListApiServicer, opts ...TodoListApiOption) Router
NewTodoListApiController creates a default api controller
type TodoListApiController ¶
type TodoListApiController struct {
// contains filtered or unexported fields
}
TodoListApiController binds http requests to an api service and writes the service results to the http response
func (*TodoListApiController) AddItem ¶
func (c *TodoListApiController) AddItem(w http.ResponseWriter, r *http.Request)
AddItem - Add a new item to the list
func (*TodoListApiController) DeleteItem ¶
func (c *TodoListApiController) DeleteItem(w http.ResponseWriter, r *http.Request)
DeleteItem - Delete an item
func (*TodoListApiController) DeleteItems ¶
func (c *TodoListApiController) DeleteItems(w http.ResponseWriter, r *http.Request)
DeleteItems - Delete all items
func (*TodoListApiController) GetItem ¶
func (c *TodoListApiController) GetItem(w http.ResponseWriter, r *http.Request)
GetItem - Get an item
func (*TodoListApiController) ListItems ¶
func (c *TodoListApiController) ListItems(w http.ResponseWriter, r *http.Request)
ListItems - List items
func (*TodoListApiController) Routes ¶
func (c *TodoListApiController) Routes() Routes
Routes returns all the api routes for the TodoListApiController
func (*TodoListApiController) UpdateItem ¶
func (c *TodoListApiController) UpdateItem(w http.ResponseWriter, r *http.Request)
UpdateItem - Update an existing item
type TodoListApiOption ¶
type TodoListApiOption func(*TodoListApiController)
TodoListApiOption for how the controller is set up.
func WithTodoListApiErrorHandler ¶
func WithTodoListApiErrorHandler(h ErrorHandler) TodoListApiOption
WithTodoListApiErrorHandler inject ErrorHandler into controller
type TodoListApiRouter ¶
type TodoListApiRouter interface { AddItem(http.ResponseWriter, *http.Request) DeleteItem(http.ResponseWriter, *http.Request) DeleteItems(http.ResponseWriter, *http.Request) GetItem(http.ResponseWriter, *http.Request) ListItems(http.ResponseWriter, *http.Request) UpdateItem(http.ResponseWriter, *http.Request) }
TodoListApiRouter defines the required methods for binding the api requests to a responses for the TodoListApi The TodoListApiRouter implementation should parse necessary information from the http request, pass the data to a TodoListApiServicer to perform the required actions, then write the service results to the http response.
type TodoListApiServicer ¶
type TodoListApiServicer interface { AddItem(context.Context, AddTodoItemRequest) (ImplResponse, error) DeleteItem(context.Context, string) (ImplResponse, error) DeleteItems(context.Context) (ImplResponse, error) GetItem(context.Context, string) (ImplResponse, error) ListItems(context.Context) (ImplResponse, error) UpdateItem(context.Context, string, UpdateTodoItemRequest) (ImplResponse, error) }
TodoListApiServicer defines the api actions for the TodoListApi 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.