Documentation
¶
Index ¶
- Constants
- func Error(w http.ResponseWriter, err error)
- func GetRemoteAddr(r *http.Request) string
- func Ok(w http.ResponseWriter)
- func OkJson(w http.ResponseWriter, v interface{})
- func Parse(r *http.Request, v interface{}) error
- func ParseForm(r *http.Request, v interface{}) error
- func ParseHeader(headerValue string) map[string]string
- func ParseHeaders(r *http.Request, v interface{}) error
- func ParseJsonBody(r *http.Request, v interface{}) error
- func ParsePath(r *http.Request, v interface{}) error
- func SetErrorHandler(handler func(error) (int, interface{}))
- func UnmarshalJsonBytes(content []byte, v interface{}) error
- func UnmarshalJsonReader(reader io.Reader, v interface{}) error
- func UnmarshalKey(m map[string]interface{}, v interface{}) error
- func ValidatePtr(v *reflect.Value) error
- func Vars(r *http.Request) map[string]string
- func WriteJson(w http.ResponseWriter, code int, v interface{})
- type MapValuer
- type Router
- type UnmarshalOption
- type Unmarshaler
- type Valuer
Constants ¶
const ( // ApplicationJson means application/json. ApplicationJson = "application/json" // ContentEncoding means Content-Encoding. ContentEncoding = "Content-Encoding" // ContentSecurity means X-Content-Security. ContentSecurity = "X-Content-Security" // ContentType means Content-Type. ContentType = "Content-Type" // 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 GetRemoteAddr ¶
GetRemoteAddr returns the peer address, supports X-Forward-For.
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.
func UnmarshalJsonBytes ¶
UnmarshalJsonBytes unmarshals content into v.
func UnmarshalJsonReader ¶
UnmarshalJsonReader unmarshals content from reader into v.
func UnmarshalKey ¶
UnmarshalKey unmarshals m into v with tag key.
func ValidatePtr ¶
ValidatePtr validates v if it's a valid pointer.
func WriteJson ¶
func WriteJson(w http.ResponseWriter, code int, v interface{})
WriteJson writes v as json string into w with code.
Types ¶
type MapValuer ¶
type MapValuer map[string]interface{}
A MapValuer is a map that can use Value method to get values with given keys.
type Router ¶
type Router interface { http.Handler Handle(method, path string, handler http.Handler) error SetNotFoundHandler(handler http.Handler) SetNotAllowedHandler(handler http.Handler) }
Router interface represents a http router that handles http requests.
type UnmarshalOption ¶
type UnmarshalOption func(*unmarshalOptions)
UnmarshalOption defines the method to customize a Unmarshaler.
func WithStringValues ¶
func WithStringValues() UnmarshalOption
WithStringValues customizes a Unmarshaler with number values from strings.
type Unmarshaler ¶
type Unmarshaler struct {
// contains filtered or unexported fields
}
A Unmarshaler is used to unmarshal with given tag key.
func NewUnmarshaler ¶
func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler
NewUnmarshaler returns a Unmarshaler.
func (*Unmarshaler) Unmarshal ¶
func (u *Unmarshaler) Unmarshal(m map[string]interface{}, v interface{}) error
Unmarshal unmarshals m into v.
func (*Unmarshaler) UnmarshalValuer ¶
func (u *Unmarshaler) UnmarshalValuer(m Valuer, v interface{}) error
UnmarshalValuer unmarshals m into v.