Documentation ¶
Index ¶
- Variables
- func GetCaller() *runtime.Frame
- func LogRequest(logger logrus.FieldLogger) func(http.Handler) http.Handler
- func MustScanJSON(dst interface{}, r io.Reader)
- func MustScanValue(dst interface{}, values url.Values)
- func Recoverer(logger logrus.FieldLogger) func(http.Handler) http.Handler
- func ScanJSON(dst interface{}, r io.Reader) error
- func ScanValues(dst interface{}, values url.Values) error
- func WriteError(w http.ResponseWriter, httpError *Error) error
- type Error
- func (e Error) Body() io.Reader
- func (e Error) Caller() (*runtime.Frame, bool)
- func (e Error) Error() string
- func (e Error) Header() http.Header
- func (e *Error) Panic()
- func (e Error) StatusCode() int
- func (e Error) Unwrap() error
- func (e *Error) WithBody(r io.Reader) *Error
- func (e *Error) WithBytes(data []byte) *Error
- func (e *Error) WithHeader(key, value string) *Error
- func (e *Error) WithJSON(v interface{}) error
- func (e *Error) WithStatus(code int) *Error
- func (e *Error) WithString(s string) *Error
- type M
- type Pagination
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Render http response content Render = renderer.New() )
View Source
var RequestDecoder = schema.NewDecoder()
RequestDecoder decode request values
View Source
var ( // RequestLogger 请求日志记录,可替换 RequestLogger = func(w http.ResponseWriter, r *http.Request, logger logrus.FieldLogger) logrus.FieldLogger { rl := r.URL fields := logrus.Fields{ "remote": r.RemoteAddr, "method": r.Method, "path": rl.Path, } if v := rl.RawQuery; v != "" { if q := rl.Query(); len(q) > 0 { fields["query"] = q } } if m := r.Method; m == http.MethodPost || m == http.MethodPut || m == http.MethodPatch { r.ParseForm() if form := r.PostForm; len(form) > 0 { fields["form"] = form } } return logger.WithFields(fields) } )
Functions ¶
func LogRequest ¶
LogRequest http访问日志
func MustScanJSON ¶
MustScanJSON json decode request body, panic when error
func MustScanValue ¶
MustScanValue deocde request values, panic when error
func ScanValues ¶
ScanValues 从url.Values解析数据
func WriteError ¶
func WriteError(w http.ResponseWriter, httpError *Error) error
WriteError write error response
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error http错误
func (*Error) WithHeader ¶
WithHeader set response header
func (*Error) WithStatus ¶
WithStatus set response status code
func (*Error) WithString ¶
WithString set response body content
type M ¶
type M map[string]interface{}
M describes handy type that represents data to send as response
Click to show internal directories.
Click to hide internal directories.