Documentation ¶
Index ¶
- Variables
- func DebugOff()
- func DebugOn()
- func ExtractFromKVS(ctx *DirectiveContext, kvs map[string][]string, isHeaderKey bool) error
- func New(inputStruct interface{}, opts ...option) (*core, error)
- func NewInput(inputStruct interface{}, opts ...option) func(http.Handler) http.Handler
- func RegisterDecoder(typ reflect.Type, decoder Decoder)
- func RegisterDirectiveExecutor(name string, exe DirectiveExecutor)
- func ReplaceDecoder(typ reflect.Type, decoder Decoder)
- func ReplaceDirectiveExecutor(name string, exe DirectiveExecutor)
- func UseGorillaMux(executor string, fnVars MuxVarsFunc)
- func WithErrorStatusCode(code int) option
- type ContextKey
- type Decoder
- type DecoderFunc
- type DirectiveContext
- type DirectiveExecutor
- type DirectiveExecutorFunc
- type FieldResolver
- type InvalidFieldError
- type MuxVarsFunc
- type UnsupportedTypeError
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ExtractFromKVS ¶
func ExtractFromKVS(ctx *DirectiveContext, kvs map[string][]string, isHeaderKey bool) error
func NewInput ¶
NewInput creates a "Middleware Constructor" for making a chain, which acts as a list of http.Handler constructors. We recommend using https://github.com/justinas/alice to chain your HTTP middleware functions and the app handler.
func RegisterDecoder ¶
RegisterDecoder registers a decoder to decode the specific type. Panics on conflicts.
func RegisterDirectiveExecutor ¶
func RegisterDirectiveExecutor(name string, exe DirectiveExecutor)
RegisterDirectiveExecutor registers a named executor globally, which implemented the DirectiveExecutor interface. Will panic if the name were taken or nil executor.
func ReplaceDecoder ¶
ReplaceDecoder replaces a decoder to decode the specific type.
func ReplaceDirectiveExecutor ¶
func ReplaceDirectiveExecutor(name string, exe DirectiveExecutor)
ReplaceDirectiveExecutor works like RegisterDirectiveExecutor without panic on duplicate names.
func UseGorillaMux ¶
func UseGorillaMux(executor string, fnVars MuxVarsFunc)
UseGorillaMux registers a new directive executor which can extract path variables from the URL.
Example: UseGorillaMux("path", mux.Vars)
type GetUserInput struct { UserID `httpin:"path=user_id"` }
func WithErrorStatusCode ¶
func WithErrorStatusCode(code int) option
Types ¶
type ContextKey ¶
type ContextKey int
const ( Input ContextKey = iota // the primary key to get the input object in the context injected by httpin FieldSet )
type DecoderFunc ¶
type DecoderFunc = internal.DecoderFunc
DecoderFunc is an adaptor to allow the use of ordinary functions as httpin decoders.
type DirectiveContext ¶
type DirectiveContext struct { ValueType reflect.Type Value reflect.Value Request *http.Request Context context.Context // contains filtered or unexported fields }
DirectiveContext holds essential information about the field being resolved and the active HTTP request. Working as the context in a directive executor.
func (*DirectiveContext) DeliverContextValue ¶
func (c *DirectiveContext) DeliverContextValue(key, value interface{})
DeliverContextValue binds a value to the specified key in the context. And it will be delivered among the executors in the same field resolver.
func (*DirectiveContext) Execute ¶
func (d *DirectiveContext) Execute(ctx *DirectiveContext) error
Execute locates the executor and runs it with the specified context.
type DirectiveExecutor ¶
type DirectiveExecutor interface {
Execute(*DirectiveContext) error
}
DirectiveExecutor is the interface implemented by a "directive executor".
type DirectiveExecutorFunc ¶
type DirectiveExecutorFunc func(*DirectiveContext) error
DirectiveExecutorFunc is an adpator to allow to use of ordinary functions as httpin.DirectiveExecutor.
func (DirectiveExecutorFunc) Execute ¶
func (f DirectiveExecutorFunc) Execute(ctx *DirectiveContext) error
Execute calls f(ctx).
type FieldResolver ¶
type FieldResolver struct { Type reflect.Type Field reflect.StructField Path []string Directives []*directive Fields []*FieldResolver }
type InvalidFieldError ¶
type InvalidFieldError struct { // Field is the name of the field. Field string `json:"field"` // Source is the directive which causes the error. // e.g. form, header, required, etc. Source string `json:"source"` // Value is the input data. Value interface{} `json:"value"` ErrorMessage string `json:"error"` // contains filtered or unexported fields }
func (*InvalidFieldError) Error ¶
func (f *InvalidFieldError) Error() string
func (*InvalidFieldError) Unwrap ¶
func (f *InvalidFieldError) Unwrap() error
type UnsupportedTypeError ¶
func (UnsupportedTypeError) Error ¶
func (e UnsupportedTypeError) Error() string
func (UnsupportedTypeError) Unwrap ¶
func (e UnsupportedTypeError) Unwrap() error