Documentation
¶
Index ¶
- func DJson[t any](b io.ReadCloser, target *t) (*t, error)
- func EJson(w io.Writer, v any) error
- func Res(status int, w http.ResponseWriter, data any)
- func ResErr(status int, w http.ResponseWriter, data any) error
- func Response(status int, w http.ResponseWriter, msg string, data any)
- func ResponseErr(status int, w http.ResponseWriter, msg string, data any) error
- func Unwrap(h WebHandler) http.HandlerFunc
- type CorsOpt
- type ErrHTTP
- type HttpResponse
- type Option
- type Server
- type WebHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DJson ¶
func DJson[t any](b io.ReadCloser, target *t) (*t, error)
DJson is a generic way to unmarshal your JSON.
func Res ¶
func Res(status int, w http.ResponseWriter, data any)
Res is a wrapper for web handlers that are compliant with the stdlib signature but returning an error.
func ResErr ¶
func ResErr(status int, w http.ResponseWriter, data any) error
ResErr is a wrapper for web handlers that are compliant with the stdlib signature but returning an error.
func Response ¶
func Response(status int, w http.ResponseWriter, msg string, data any)
Response is a wrapper for web handlers that are compliant with the stdlib.
func ResponseErr ¶
ResponseErr is a wrapper for web handlers that are compliant with the stdlib signature but returning an error.
func Unwrap ¶
func Unwrap(h WebHandler) http.HandlerFunc
Types ¶
type HttpResponse ¶
type Option ¶ added in v0.1.2
type Option func(options *options)
func WithCompress ¶ added in v0.1.2
WithCompress you can add a compress middleware. NOTE: make sure to set the Content-Type header on your response otherwise this middleware will not compress the response body. For ex, in your handler you should set w.Header().Set("Content-Type", http.DetectContentType(yourBody)) or set it manually.
Passing a compression level of 5 is sensible value
func WithCors ¶ added in v0.1.2
WithCors add cors to your web server. AllowedMethods example {"GET", "POST", "PUT", "DELETE", "OPTIONS"}.
func WithHeartbeat ¶ added in v0.1.2
WithHeartbeat add a dummy endpoint in the specified path. Will return a non-json response "." with a 200 status.
type Server ¶
func NewServer ¶
NewServer return a *Server. Including Logger will include also recoverer and requestID middlewares.
func (*Server) FileServer ¶ added in v0.1.2
FileServer will be used to serve the static files, please specify the route.
type WebHandler ¶
type WebHandler func(w http.ResponseWriter, r *http.Request) error