Documentation ¶
Index ¶
- Constants
- func Error(w http.ResponseWriter, err error, ...)
- func ErrorCtx(ctx context.Context, w http.ResponseWriter, err error, ...)
- func GetFormValues(r *http.Request) (map[string]any, error)
- func GetRemoteAddr(r *http.Request) string
- func Ok(w http.ResponseWriter)
- func OkJson(w http.ResponseWriter, v any)
- func OkJsonCtx(ctx context.Context, w http.ResponseWriter, v any)
- func Parse(r *http.Request, v any) error
- func ParseForm(r *http.Request, v any) error
- func ParseHeader(headerValue string) map[string]string
- func ParseHeaders(r *http.Request, v any) error
- func ParseJsonBody(r *http.Request, v any) error
- func ParsePath(r *http.Request, v any) error
- func SetErrorHandler(handler func(error) (int, any))
- func SetErrorHandlerCtx(handlerCtx func(context.Context, error) (int, any))
- func SetOkHandler(handler func(context.Context, any) any)
- func SetValidator(val Validator)
- func Stream(ctx context.Context, w http.ResponseWriter, fn func(w io.Writer) bool)
- func WriteJson(w http.ResponseWriter, code int, v any)
- func WriteJsonCtx(ctx context.Context, w http.ResponseWriter, code int, v any)
- type Router
- type Validator
Constants ¶
const ( // ContentEncoding means Content-Encoding. ContentEncoding = "Content-Encoding" // ContentSecurity means X-Content-Security. ContentSecurity = "X-Content-Security" // ContentType means Content-Type. ContentType = header.ContentType // JsonContentType means application/json. JsonContentType = header.JsonContentType // KeyField means key. KeyField = "key" // SecretField means secret. SecretField = "secret" // TypeField means type. TypeField = "type" // CryptionType means cryption. CryptionType = 1 )
const ( // CodeSignaturePass means signature verification passed. CodeSignaturePass = iota // CodeSignatureInvalidHeader means invalid header in signature. CodeSignatureInvalidHeader // CodeSignatureWrongTime means wrong timestamp in signature. CodeSignatureWrongTime // CodeSignatureInvalidToken means invalid token in signature. CodeSignatureInvalidToken )
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, err error, fns ...func(w http.ResponseWriter, err error))
Error writes err into w.
func ErrorCtx ¶ added in v1.4.3
func ErrorCtx(ctx context.Context, w http.ResponseWriter, err error, fns ...func(w http.ResponseWriter, err error))
ErrorCtx writes err into w.
func GetFormValues ¶ added in v1.4.0
GetFormValues returns the form values.
func GetRemoteAddr ¶
GetRemoteAddr returns the peer address, supports X-Forward-For.
func OkJsonCtx ¶ added in v1.4.3
func OkJsonCtx(ctx context.Context, w http.ResponseWriter, v any)
OkJsonCtx writes v into w with 200 OK.
func ParseHeader ¶
ParseHeader parses the request header and returns a map.
func ParseHeaders ¶
ParseHeaders parses the headers request.
func ParseJsonBody ¶
ParseJsonBody parses the post request which contains json in body.
func ParsePath ¶
ParsePath parses the symbols reside in url path. Like http://localhost/bag/:name
func SetErrorHandler ¶
SetErrorHandler sets the error handler, which is called on calling Error. Notice: SetErrorHandler and SetErrorHandlerCtx set the same error handler. Keeping both SetErrorHandler and SetErrorHandlerCtx is for backward compatibility.
func SetErrorHandlerCtx ¶ added in v1.4.3
SetErrorHandlerCtx sets the error handler, which is called on calling Error. Notice: SetErrorHandler and SetErrorHandlerCtx set the same error handler. Keeping both SetErrorHandler and SetErrorHandlerCtx is for backward compatibility.
func SetOkHandler ¶ added in v1.5.4
SetOkHandler sets the response handler, which is called on calling OkJson and OkJsonCtx.
func SetValidator ¶ added in v1.4.5
func SetValidator(val Validator)
SetValidator sets the validator. The validator is used to validate the request, only called in Parse, not in ParseHeaders, ParseForm, ParseHeader, ParseJsonBody, ParsePath.
func Stream ¶ added in v1.6.4
Stream writes data into w with streaming mode. The ctx is used to control the streaming loop, typically use r.Context(). The fn is called repeatedly until it returns false.
func WriteJson ¶
func WriteJson(w http.ResponseWriter, code int, v any)
WriteJson writes v as json string into w with code.
func WriteJsonCtx ¶ added in v1.4.3
WriteJsonCtx writes v as json string into w with code.