Documentation ¶
Index ¶
- Variables
- func NewError(message string) error
- func NewErrorCode(code, message string) error
- func NewProtocolError(code, message string) error
- func WrapError(err error) error
- type Decoder
- type Empty
- type Encoder
- type Error
- type ErrorEncoder
- type FormUnmarshaler
- type Manager
- func (m *Manager) Decode(r *http.Request, v any) error
- func (m *Manager) Encode(w http.ResponseWriter, r *http.Request, v any)
- func (m *Manager) EncodeError(w http.ResponseWriter, r *http.Request, err error)
- func (m *Manager) Handler(f any) http.Handler
- func (m *Manager) Middleware(f Middleware) func(http.Handler) http.Handler
- func (m *Manager) NotFound(w http.ResponseWriter, r *http.Request)
- func (m *Manager) NotFoundHandler() http.Handler
- func (m *Manager) OnError(f func(w http.ResponseWriter, r *http.Request, req any, err error))
- func (m *Manager) OnOK(f func(w http.ResponseWriter, r *http.Request, req any, res any))
- type Middleware
- type MiddlewareContext
- func (ctx *MiddlewareContext) Deadline() (deadline time.Time, ok bool)
- func (ctx *MiddlewareContext) Done() <-chan struct{}
- func (ctx *MiddlewareContext) Err() error
- func (ctx *MiddlewareContext) Request() *http.Request
- func (ctx *MiddlewareContext) ResponseWriter() http.ResponseWriter
- func (ctx *MiddlewareContext) SetRequest(r *http.Request)
- func (ctx *MiddlewareContext) SetRequestContext(nctx context.Context)
- func (ctx *MiddlewareContext) SetResponseWriter(w http.ResponseWriter)
- func (ctx *MiddlewareContext) Value(key interface{}) interface{}
- type MultipartFormUnmarshaler
- type OKError
- type ProtocolError
- type RequestAdapter
- type RequestUnmarshaler
- type Validatable
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = NewProtocolError("", "not found") ErrUnsupported = NewProtocolError("", "unsupported content type") )
predefined errors
Functions ¶
func NewErrorCode ¶ added in v2.1.0
NewErrorCode creates new Error with code and message
func NewProtocolError ¶
Types ¶
type Empty ¶ added in v2.1.0
type Empty struct{}
func (Empty) UnmarshalMultipartForm ¶ added in v2.1.0
type Encoder ¶ added in v2.1.0
type Encoder func(http.ResponseWriter, *http.Request, any)
Encoder is the response encoder
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error always return 200 status with false ok value use this error for validate, precondition failed, etc.
func (*Error) MarshalJSON ¶
MarshalJSON implements json.Marshaler
type ErrorEncoder ¶ added in v2.1.0
type ErrorEncoder func(http.ResponseWriter, *http.Request, error)
ErrorEncoder is the error response encoder
type FormUnmarshaler ¶
FormUnmarshaler interface
type Manager ¶
type Manager struct { Decoder Decoder Encoder Encoder ErrorEncoder ErrorEncoder Validate bool // set to true to validate request after decode using Validatable interface WrapError func(error) error // contains filtered or unexported fields }
func (*Manager) EncodeError ¶ added in v2.0.1
func (*Manager) Middleware ¶ added in v2.1.3
func (*Manager) NotFoundHandler ¶
type Middleware ¶ added in v2.1.3
type Middleware func(r *MiddlewareContext) error
type MiddlewareContext ¶ added in v2.1.4
type MiddlewareContext struct {
// contains filtered or unexported fields
}
func (*MiddlewareContext) Deadline ¶ added in v2.1.4
func (ctx *MiddlewareContext) Deadline() (deadline time.Time, ok bool)
func (*MiddlewareContext) Done ¶ added in v2.1.4
func (ctx *MiddlewareContext) Done() <-chan struct{}
func (*MiddlewareContext) Err ¶ added in v2.1.4
func (ctx *MiddlewareContext) Err() error
func (*MiddlewareContext) Request ¶ added in v2.1.4
func (ctx *MiddlewareContext) Request() *http.Request
func (*MiddlewareContext) ResponseWriter ¶ added in v2.1.4
func (ctx *MiddlewareContext) ResponseWriter() http.ResponseWriter
func (*MiddlewareContext) SetRequest ¶ added in v2.1.5
func (ctx *MiddlewareContext) SetRequest(r *http.Request)
func (*MiddlewareContext) SetRequestContext ¶ added in v2.1.5
func (ctx *MiddlewareContext) SetRequestContext(nctx context.Context)
func (*MiddlewareContext) SetResponseWriter ¶ added in v2.1.5
func (ctx *MiddlewareContext) SetResponseWriter(w http.ResponseWriter)
func (*MiddlewareContext) Value ¶ added in v2.1.4
func (ctx *MiddlewareContext) Value(key interface{}) interface{}
type MultipartFormUnmarshaler ¶
MultipartFormUnmarshaler interface
type OKError ¶
type OKError interface {
OKError()
}
OKError implements this interface to mark errors as 200
type ProtocolError ¶
type ProtocolError struct { Code string `json:"code,omitempty"` Message string `json:"message,omitempty"` }
ProtocolError always returns 400 status with false ok value only use this error for invalid protocol usages
func (*ProtocolError) Error ¶
func (err *ProtocolError) Error() string
type RequestAdapter ¶
RequestAdapter converts request to arpc before decode
type RequestUnmarshaler ¶
RequestUnmarshaler interface
type Validatable ¶ added in v2.1.0
type Validatable interface {
Valid() error
}
Validatable interface
Click to show internal directories.
Click to hide internal directories.