Documentation
¶
Index ¶
- Variables
- func AssertErrorConstraints(obj Error) error
- func AssertErrorRequired(obj Error) error
- func AssertRecurseInterfaceRequired[T any](obj interface{}, callback func(T) error) error
- func AssertRecurseValueRequired[T any](value reflect.Value, callback func(T) error) error
- func AssertUrlConstraints(obj Url) error
- func AssertUrlRequired(obj Url) error
- func DefaultErrorHandler(w http.ResponseWriter, _ *http.Request, err error, result *ImplResponse)
- func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, 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 Constraint
- type Error
- type ErrorHandler
- type ImplResponse
- type Number
- type Operation
- type ParseString
- type ParsingError
- type RequiredError
- type Route
- type Router
- type Routes
- type URLAPIController
- func (c *URLAPIController) CreateUrl(w http.ResponseWriter, r *http.Request)
- func (c *URLAPIController) DeleteUrl(w http.ResponseWriter, r *http.Request)
- func (c *URLAPIController) GetUrl(w http.ResponseWriter, r *http.Request)
- func (c *URLAPIController) GetUrlData(w http.ResponseWriter, r *http.Request)
- func (c *URLAPIController) Routes() Routes
- type URLAPIOption
- type URLAPIRouter
- type URLAPIServicer
- type Url
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 AssertErrorConstraints ¶
AssertErrorConstraints checks if the values respects the defined constraints
func AssertErrorRequired ¶
AssertErrorRequired checks if the required fields are not zero-ed
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. ErrTypeAssertionError is thrown if the underlying struct does not match type T.
func AssertUrlConstraints ¶
AssertUrlConstraints checks if the values respects the defined constraints
func AssertUrlRequired ¶
AssertUrlRequired checks if the required fields are not zero-ed
func DefaultErrorHandler ¶
func DefaultErrorHandler(w http.ResponseWriter, _ *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, headers map[string][]string, 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 Constraint ¶
func WithMaximum ¶
func WithMaximum[T Number](expected T) Constraint[T]
func WithMinimum ¶
func WithMinimum[T Number](expected T) Constraint[T]
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 ¶
ImplResponse defines an implementation response with error code and the associated body
func Response ¶
func Response(code int, body interface{}) ImplResponse
Response return a ImplResponse struct filled
func ResponseWithHeaders ¶
func ResponseWithHeaders(code int, headers map[string][]string, body interface{}) ImplResponse
ResponseWithHeaders return a ImplResponse struct filled, including headers
type Operation ¶
func WithDefaultOrParse ¶
func WithDefaultOrParse[T Number | string | bool](def T, parse ParseString[T]) Operation[T]
func WithRequire ¶
func WithRequire[T Number | string | bool](parse ParseString[T]) Operation[T]
type ParsingError ¶
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 { 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
type URLAPIController ¶
type URLAPIController struct {
// contains filtered or unexported fields
}
URLAPIController binds http requests to an api service and writes the service results to the http response
func NewURLAPIController ¶
func NewURLAPIController(s URLAPIServicer, opts ...URLAPIOption) *URLAPIController
NewURLAPIController creates a default api controller
func (*URLAPIController) CreateUrl ¶
func (c *URLAPIController) CreateUrl(w http.ResponseWriter, r *http.Request)
CreateUrl - Create a new url
func (*URLAPIController) DeleteUrl ¶
func (c *URLAPIController) DeleteUrl(w http.ResponseWriter, r *http.Request)
DeleteUrl - Delete a url
func (*URLAPIController) GetUrl ¶
func (c *URLAPIController) GetUrl(w http.ResponseWriter, r *http.Request)
GetUrl - Get a url
func (*URLAPIController) GetUrlData ¶
func (c *URLAPIController) GetUrlData(w http.ResponseWriter, r *http.Request)
GetUrlData - Returns a url metadata
func (*URLAPIController) Routes ¶
func (c *URLAPIController) Routes() Routes
Routes returns all the api routes for the URLAPIController
type URLAPIOption ¶
type URLAPIOption func(*URLAPIController)
URLAPIOption for how the controller is set up.
func WithURLAPIErrorHandler ¶
func WithURLAPIErrorHandler(h ErrorHandler) URLAPIOption
WithURLAPIErrorHandler inject ErrorHandler into controller
type URLAPIRouter ¶
type URLAPIRouter interface { GetUrl(http.ResponseWriter, *http.Request) DeleteUrl(http.ResponseWriter, *http.Request) GetUrlData(http.ResponseWriter, *http.Request) CreateUrl(http.ResponseWriter, *http.Request) }
URLAPIRouter defines the required methods for binding the api requests to a responses for the URLAPI The URLAPIRouter implementation should parse necessary information from the http request, pass the data to a URLAPIServicer to perform the required actions, then write the service results to the http response.
type URLAPIServicer ¶
type URLAPIServicer interface { GetUrl(context.Context, string, string) (ImplResponse, error) DeleteUrl(context.Context, string, string) (ImplResponse, error) GetUrlData(context.Context, string, string) (ImplResponse, error) CreateUrl(context.Context, Url, string) (ImplResponse, error) }
URLAPIServicer defines the api actions for the URLAPI 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.