Documentation
¶
Index ¶
- Constants
- func Default[Body any, Err any](w http.ResponseWriter, body Body, responseErr Err, status int)
- func ErrorResponse[Err any](w http.ResponseWriter, responseErr Err, status int)
- func SuccessResponse[Body any](w http.ResponseWriter, body Body, status int)
- type CallerFunc
- type DefaultResponse
- type HandlerMaker
- func (h *HandlerMaker[ReqT, RespT]) Run(successStatus int)
- func (h *HandlerMaker[ReqT, RespT]) WithJson() *HandlerMaker[ReqT, RespT]
- func (h *HandlerMaker[ReqT, RespT]) WithMultipart(maxMemory int64) *HandlerMaker[ReqT, RespT]
- func (h *HandlerMaker[ReqT, RespT]) WithQuery() *HandlerMaker[ReqT, RespT]
- func (h *HandlerMaker[ReqT, RespT]) WithVars() *HandlerMaker[ReqT, RespT]
- type Logger
Constants ¶
View Source
const ( ErrNotValidBodyFormat = "unable to unmarshal request body " ErrEmptyMultipartData = "empty multipart form data " )
Variables ¶
This section is empty.
Functions ¶
func Default ¶
func Default[Body any, Err any](w http.ResponseWriter, body Body, responseErr Err, status int)
func ErrorResponse ¶
func ErrorResponse[Err any](w http.ResponseWriter, responseErr Err, status int)
func SuccessResponse ¶
func SuccessResponse[Body any](w http.ResponseWriter, body Body, status int)
Types ¶
type CallerFunc ¶
type CallerFunc[ReqT any, RespT any] func(ctx context.Context, req ReqT) (RespT, tiny_errors.ErrorHandler)
type DefaultResponse ¶
type HandlerMaker ¶
func New ¶
func New[ReqT any, RespT any](w http.ResponseWriter, r *http.Request, logger Logger, caller CallerFunc[ReqT, RespT]) *HandlerMaker[ReqT, RespT]
func (*HandlerMaker[ReqT, RespT]) Run ¶
func (h *HandlerMaker[ReqT, RespT]) Run(successStatus int)
func (*HandlerMaker[ReqT, RespT]) WithJson ¶
func (h *HandlerMaker[ReqT, RespT]) WithJson() *HandlerMaker[ReqT, RespT]
Request type should include fields with tags of json
Example:
type YourRequest struct {
FieldName string `json:"field_name"`
}
func (*HandlerMaker[ReqT, RespT]) WithMultipart ¶
func (h *HandlerMaker[ReqT, RespT]) WithMultipart(maxMemory int64) *HandlerMaker[ReqT, RespT]
Request type should include fields with tags of mapstructure
If field is an array of files you should set tag name as files[] and type []*multipart.FileHeader(mime/multipart.FileHeader)
If field is file and not array of files you should set tag with field name without brackets and type *multipart.FileHeader(mime/multipart.FileHeader)
Other fields should have string type(mime/multipart.Form)
File types ¶
- []*multipart.FileHeader - field with array of files. Should contain square brackets in name
- *multipart.FileHeader - field with single file. Should not contain square brackets in field name
Example ¶
type YourRequest struct {
MultipleFiles []*multipart.FileHeader `mapstructure:"your_files[]"`
SingleFile *multipart.FileHeader `mapstructure:"single_file"`
Name string `mapstructure:"name"`
}
func (*HandlerMaker[ReqT, RespT]) WithQuery ¶
func (h *HandlerMaker[ReqT, RespT]) WithQuery() *HandlerMaker[ReqT, RespT]
Request type should include fields with tags of mapstructure
Example:
type YourRequest struct {
FieldName string `mapstructure:"field_name"`
}
func (*HandlerMaker[ReqT, RespT]) WithVars ¶
func (h *HandlerMaker[ReqT, RespT]) WithVars() *HandlerMaker[ReqT, RespT]
Request type should include fields with tags of mapstructure
Example:
type YourRequest struct {
FieldName string `mapstructure:"field_name"`
}
Click to show internal directories.
Click to hide internal directories.