Documentation ¶
Index ¶
- Constants
- Variables
- func Error(w http.ResponseWriter, err error)
- func ErrorJson(w http.ResponseWriter, err error, v interface{})
- 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 ParseJsonBody(r *http.Request, v interface{}) error
- func ParsePath(r *http.Request, v interface{}) error
- func SetErrorHandler(handler func(error) (int, interface{}))
- func WriteJson(w http.ResponseWriter, code int, v interface{})
- type ResponseError
- type ResponseErrorOption
- type Router
Constants ¶
View Source
const ( RequestSuccessCode = 0 RequestSuccessMsg = "request successes." RequestBadCode = 400 RequestBadMsg = "request failed." )
View Source
const ( ApplicationJson = "application/json" ContentEncoding = "Content-Encoding" ContentSecurity = "X-Content-Security" ContentType = "Content-Type" KeyField = "key" SecretField = "secret" TypeField = "type" CryptionType = 1 )
View Source
const ( CodeSignaturePass = iota CodeSignatureInvalidHeader CodeSignatureWrongTime CodeSignatureInvalidToken )
Variables ¶
View Source
var GrpcCodeMap = map[codes.Code]int64{ codes.OK: 10000, codes.Canceled: 11000, codes.Unknown: 12000, codes.InvalidArgument: 13000, codes.DeadlineExceeded: 14000, codes.NotFound: 15000, codes.AlreadyExists: 16000, codes.PermissionDenied: 17000, codes.ResourceExhausted: 18000, codes.FailedPrecondition: 19000, codes.Aborted: 20000, codes.OutOfRange: 21000, codes.Unimplemented: 22000, codes.Internal: 23000, codes.Unavailable: 24000, codes.DataLoss: 25000, codes.Unauthenticated: 26000, }
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, err error)
func ErrorJson ¶
func ErrorJson(w http.ResponseWriter, err error, v interface{})
func GetRemoteAddr ¶
Returns the peer address, supports X-Forward-For
func Ok ¶
func Ok(w http.ResponseWriter)
func OkJson ¶
func OkJson(w http.ResponseWriter, v interface{})
func ParseHeader ¶
func ParseJsonBody ¶
Parses the post request which contains json in body.
func ParsePath ¶
Parses the symbols reside in url path. Like http://localhost/bag/:name
func SetErrorHandler ¶
func WriteJson ¶
func WriteJson(w http.ResponseWriter, code int, v interface{})
Types ¶
type ResponseError ¶
type ResponseError struct { Code int64 `json:"code"` Msg string `json:"msg"` Data interface{} `json:"data"` }
func NewResponseError ¶
func NewResponseError(option ...ResponseErrorOption) *ResponseError
func (ResponseError) Error ¶
func (e ResponseError) Error() string
func (*ResponseError) Is ¶
func (e *ResponseError) Is(target error) bool
type ResponseErrorOption ¶
type ResponseErrorOption func(responseError *ResponseError)
func CodeOption ¶
func CodeOption(code int64) ResponseErrorOption
func DataOption ¶
func DataOption(data interface{}) ResponseErrorOption
func MsgOption ¶
func MsgOption(msg string) ResponseErrorOption
Click to show internal directories.
Click to hide internal directories.