middleware

package
v0.0.0-...-fab8377 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 14 Imported by: 0

README

Middleware

  • safe.go

mainly about safahandler

  • param.go

parse params each handler need

  • response.go

response to client

  • reqlog.go

log request related info with logger

Documentation

Overview

Package middleware include param, reqlog, response, safe related functional modules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestLog

func RequestLog(req *http.Request) string

RequestLog to log http.Request values

func ResponseErrorJson

func ResponseErrorJson(w http.ResponseWriter, je interface{})

ResponseErrorJson response JsonErr data to client

func ResponseJson

func ResponseJson(w http.ResponseWriter, i interface{})

ResponseJson response interface{} as json string to client

func SafeHandler

func SafeHandler(w http.ResponseWriter, req *http.Request)

SafeHandler recover from panic will be used in `Handler.ServeHTTP`

Types

type Errors

type Errors []*valid.Error

Errors saved errs in valid.Error type

type ParamError

type ParamError struct {
	Field   string      `json:"field"`
	Value   interface{} `json:"value"`
	Message string      `json:"message"`
}

ParamError include Field, Value, Message

func NewParamError

func NewParamError(field, message string, value interface{}) *ParamError

new ParamError with (field, message string, value interface{})

func NewParamErrorFromValidError

func NewParamErrorFromValidError(ve *valid.Error) *ParamError

new ParamError from valid.Error

func ParseParams

func ParseParams(w http.ResponseWriter, req *http.Request, reqRes interface{}) (errs []*ParamError)

ParseParams, parse params into reqRes from req.Form, and support form-data, json-body TODO: support parse file

func (*ParamError) Error

func (pe *ParamError) Error() string

Error stringfiy ParamError

func (*ParamError) String

func (pe *ParamError) String() string

String of ParamError, to format as string

type ParamFile

type ParamFile struct {
	File       multipart.File
	FileHeader multipart.FileHeader
}

ParamFile to save file from request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL