Documentation
¶
Index ¶
- Variables
- func AssertAmountConstraints(obj Amount) error
- func AssertAmountRequired(obj Amount) error
- func AssertCommentRequestConstraints(obj CommentRequest) error
- func AssertCommentRequestRequired(obj CommentRequest) error
- func AssertErrorConstraints(obj Error) error
- func AssertErrorRequired(obj Error) error
- func AssertLoginRequestConstraints(obj LoginRequest) error
- func AssertLoginRequestRequired(obj LoginRequest) 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 AssertStatisticConstraints(obj Statistic) error
- func AssertStatisticRequired(obj Statistic) error
- func AssertStatisticsResponseConstraints(obj StatisticsResponse) error
- func AssertStatisticsResponseRequired(obj StatisticsResponse) 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) *mux.Router
- func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)
- func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)
- type Amount
- type AuthenticationAPIController
- type AuthenticationAPIOption
- type AuthenticationAPIRouter
- type AuthenticationAPIServicer
- type CommentAPIController
- type CommentAPIOption
- type CommentAPIRouter
- type CommentAPIServicer
- type CommentRequest
- type Constraint
- type Error
- type ErrorHandler
- type ImplResponse
- type LoginRequest
- type Number
- type Operation
- type ParseString
- type ParsingError
- type RequiredError
- type Route
- type Router
- type Routes
- type Statistic
- type StatisticsAPIController
- type StatisticsAPIOption
- type StatisticsAPIRouter
- type StatisticsAPIServicer
- type StatisticsResponse
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 AssertAmountConstraints ¶
AssertAmountConstraints checks if the values respects the defined constraints
func AssertAmountRequired ¶
AssertAmountRequired checks if the required fields are not zero-ed
func AssertCommentRequestConstraints ¶
func AssertCommentRequestConstraints(obj CommentRequest) error
AssertCommentRequestConstraints checks if the values respects the defined constraints
func AssertCommentRequestRequired ¶
func AssertCommentRequestRequired(obj CommentRequest) error
AssertCommentRequestRequired checks if the required fields are not zero-ed
func AssertErrorConstraints ¶
AssertErrorConstraints checks if the values respects the defined constraints
func AssertErrorRequired ¶
AssertErrorRequired checks if the required fields are not zero-ed
func AssertLoginRequestConstraints ¶
func AssertLoginRequestConstraints(obj LoginRequest) error
AssertLoginRequestConstraints checks if the values respects the defined constraints
func AssertLoginRequestRequired ¶
func AssertLoginRequestRequired(obj LoginRequest) error
AssertLoginRequestRequired 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 AssertStatisticConstraints ¶
AssertStatisticConstraints checks if the values respects the defined constraints
func AssertStatisticRequired ¶
AssertStatisticRequired checks if the required fields are not zero-ed
func AssertStatisticsResponseConstraints ¶
func AssertStatisticsResponseConstraints(obj StatisticsResponse) error
AssertStatisticsResponseConstraints checks if the values respects the defined constraints
func AssertStatisticsResponseRequired ¶
func AssertStatisticsResponseRequired(obj StatisticsResponse) error
AssertStatisticsResponseRequired 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 ReadFormFileToTempFile ¶
ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
Types ¶
type AuthenticationAPIController ¶
type AuthenticationAPIController struct {
// contains filtered or unexported fields
}
AuthenticationAPIController binds http requests to an api service and writes the service results to the http response
func (*AuthenticationAPIController) PostLogin ¶
func (c *AuthenticationAPIController) PostLogin(w http.ResponseWriter, r *http.Request)
PostLogin - provides JWT token
func (*AuthenticationAPIController) Routes ¶
func (c *AuthenticationAPIController) Routes() Routes
Routes returns all the api routes for the AuthenticationAPIController
type AuthenticationAPIOption ¶
type AuthenticationAPIOption func(*AuthenticationAPIController)
AuthenticationAPIOption for how the controller is set up.
func WithAuthenticationAPIErrorHandler ¶
func WithAuthenticationAPIErrorHandler(h ErrorHandler) AuthenticationAPIOption
WithAuthenticationAPIErrorHandler inject ErrorHandler into controller
type AuthenticationAPIRouter ¶
type AuthenticationAPIRouter interface {
PostLogin(http.ResponseWriter, *http.Request)
}
AuthenticationAPIRouter defines the required methods for binding the api requests to a responses for the AuthenticationAPI The AuthenticationAPIRouter implementation should parse necessary information from the http request, pass the data to a AuthenticationAPIServicer to perform the required actions, then write the service results to the http response.
type AuthenticationAPIServicer ¶
type AuthenticationAPIServicer interface {
PostLogin(context.Context, LoginRequest) (ImplResponse, error)
}
AuthenticationAPIServicer defines the api actions for the AuthenticationAPI 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.
type CommentAPIController ¶
type CommentAPIController struct {
// contains filtered or unexported fields
}
CommentAPIController binds http requests to an api service and writes the service results to the http response
func (*CommentAPIController) PostComment ¶
func (c *CommentAPIController) PostComment(w http.ResponseWriter, r *http.Request)
PostComment - Saves a new Comment
func (*CommentAPIController) Routes ¶
func (c *CommentAPIController) Routes() Routes
Routes returns all the api routes for the CommentAPIController
type CommentAPIOption ¶
type CommentAPIOption func(*CommentAPIController)
CommentAPIOption for how the controller is set up.
func WithCommentAPIErrorHandler ¶
func WithCommentAPIErrorHandler(h ErrorHandler) CommentAPIOption
WithCommentAPIErrorHandler inject ErrorHandler into controller
type CommentAPIRouter ¶
type CommentAPIRouter interface {
PostComment(http.ResponseWriter, *http.Request)
}
CommentAPIRouter defines the required methods for binding the api requests to a responses for the CommentAPI The CommentAPIRouter implementation should parse necessary information from the http request, pass the data to a CommentAPIServicer to perform the required actions, then write the service results to the http response.
type CommentAPIServicer ¶
type CommentAPIServicer interface {
PostComment(context.Context, int32, string, CommentRequest) (ImplResponse, error)
}
CommentAPIServicer defines the api actions for the CommentAPI 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.
type CommentRequest ¶
type CommentRequest struct {
Content string `json:"content"`
}
type Constraint ¶
func WithMaximum ¶
func WithMaximum[T Number](expected T) Constraint[T]
func WithMinimum ¶
func WithMinimum[T Number](expected T) Constraint[T]
type Error ¶
type Error struct { // Error message Message string `json:"message"` // The timestamp the error has occured Timestamp string `json:"timestamp"` }
Error - Error object
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 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
type LoginRequest ¶
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 ¶
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 { 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 NewAuthenticationAPIController ¶
func NewAuthenticationAPIController(s AuthenticationAPIServicer, opts ...AuthenticationAPIOption) Router
NewAuthenticationAPIController creates a default api controller
func NewCommentAPIController ¶
func NewCommentAPIController(s CommentAPIServicer, opts ...CommentAPIOption) Router
NewCommentAPIController creates a default api controller
func NewStatisticsAPIController ¶
func NewStatisticsAPIController(s StatisticsAPIServicer, opts ...StatisticsAPIOption) Router
NewStatisticsAPIController creates a default api controller
type StatisticsAPIController ¶
type StatisticsAPIController struct {
// contains filtered or unexported fields
}
StatisticsAPIController binds http requests to an api service and writes the service results to the http response
func (*StatisticsAPIController) GetStatistics ¶
func (c *StatisticsAPIController) GetStatistics(w http.ResponseWriter, r *http.Request)
GetStatistics - Provides statistics about user activity
func (*StatisticsAPIController) Routes ¶
func (c *StatisticsAPIController) Routes() Routes
Routes returns all the api routes for the StatisticsAPIController
type StatisticsAPIOption ¶
type StatisticsAPIOption func(*StatisticsAPIController)
StatisticsAPIOption for how the controller is set up.
func WithStatisticsAPIErrorHandler ¶
func WithStatisticsAPIErrorHandler(h ErrorHandler) StatisticsAPIOption
WithStatisticsAPIErrorHandler inject ErrorHandler into controller
type StatisticsAPIRouter ¶
type StatisticsAPIRouter interface {
GetStatistics(http.ResponseWriter, *http.Request)
}
StatisticsAPIRouter defines the required methods for binding the api requests to a responses for the StatisticsAPI The StatisticsAPIRouter implementation should parse necessary information from the http request, pass the data to a StatisticsAPIServicer to perform the required actions, then write the service results to the http response.
type StatisticsAPIServicer ¶
type StatisticsAPIServicer interface {
GetStatistics(context.Context, int32) (ImplResponse, error)
}
StatisticsAPIServicer defines the api actions for the StatisticsAPI 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.