Documentation
¶
Index ¶
- Constants
- func EnforceCreate(payload interface{}) (err error)
- func EnforceUpdate(original, update interface{}) (err error)
- func ProvideJSONDecoder(parent context.Context, r *http.Request) context.Context
- func WithDecoder(parent context.Context, provider DecoderProvider) context.Context
- func WithPartialDecoder(parent context.Context, provider DecoderProvider) context.Context
- type Decoder
- type DecoderProvider
- type Desc
- type MWCond
- type Middleware
- type Middlewares
- func (wares *Middlewares) Add(weight int, waresToAdd ...endpoint.Middleware)
- func (wares Middlewares) Chain() endpoint.Middleware
- func (wares Middlewares) Len() int
- func (wares Middlewares) Less(i, j int) bool
- func (wares *Middlewares) Remove(cond MWCond)
- func (wares Middlewares) Slice() (slice []endpoint.Middleware)
- func (wares Middlewares) Swap(i, j int)
- type Noun
- type Paths
- type Request
- type RouterFunc
- type Service
- type ServiceSlice
- type Services
- type ServicesPatch
Constants ¶
const ( MWOuter = -10 MWProtocol = -5 MWPrepare = -1 MWNormal = 0 MWInner = 10 )
weight of different middlewares
MWOuter is for middleware that runs before any protocol read or / and after any protocol output
MWProtocol is for middleware that unwrap decoded request from a protocol or wraps the results in a proper line protocol before encode
MWPrepare is for middleware to prepare the request before endpoint or prepare the response before protocol
MWNormal is reserved for any
MWInner is for middleware to run between normal middleware and the endpoint
Variables ¶
This section is empty.
Functions ¶
func EnforceCreate ¶
func EnforceCreate(payload interface{}) (err error)
EnforceCreate enforce some field on creation, as defined in struct field tags
func EnforceUpdate ¶
func EnforceUpdate(original, update interface{}) (err error)
EnforceUpdate enforce some fields value on update, as defined in struct field tags
func ProvideJSONDecoder ¶
ProvideJSONDecoder provides JSON encoder with a given *http.Request to context
func WithDecoder ¶
func WithDecoder(parent context.Context, provider DecoderProvider) context.Context
WithDecoder adds a decoder to context so you can latter retrieve with DecoderFrom(context)
func WithPartialDecoder ¶
func WithPartialDecoder(parent context.Context, provider DecoderProvider) context.Context
WithPartialDecoder adds a decoder to context so you can latter retrieve with DecoderFrom(context)
Types ¶
type Decoder ¶
type Decoder interface {
Decode(v interface{}) (err error)
}
Decoder decodes streams it receives to the pointer v provided
func DecoderFrom ¶
DecoderFrom gets decoder set to the context
type DecoderProvider ¶
DecoderProvider provides decoder
type Desc ¶
type Desc interface { Paths() Paths SetMiddleware(name string, mware endpoint.Middleware) GetMiddleware(name string) endpoint.Middleware SetDecodeFunc(name string, dec httptransport.DecodeRequestFunc) GetDecodeFunc(name string) httptransport.DecodeRequestFunc }
Desc is the descriptor of a RESTful service
type MWCond ¶
type MWCond func(mw Middleware) bool
MWCond is the condition for removing middleware in a set
type Middleware ¶
type Middleware struct { endpoint.Middleware Weight int }
Middleware wrap a middleware with a weight parameter
type Middlewares ¶
type Middlewares []Middleware
Middlewares contain middlewares to use in the service
func (*Middlewares) Add ¶
func (wares *Middlewares) Add(weight int, waresToAdd ...endpoint.Middleware)
Add appends a middleware to the set
func (Middlewares) Chain ¶
func (wares Middlewares) Chain() endpoint.Middleware
Chain is the helper function for composing middlewares in specific order
func (Middlewares) Less ¶
func (wares Middlewares) Less(i, j int) bool
Less implements sort.Interface
func (*Middlewares) Remove ¶
func (wares *Middlewares) Remove(cond MWCond)
Remove removes a middleware by condition
func (Middlewares) Slice ¶
func (wares Middlewares) Slice() (slice []endpoint.Middleware)
Slice returns a sorted []endpoint.Middleware
type Request ¶
type Request struct { // Request stores the raw *http.Request Request *http.Request // Query stores the parsed Query information Query store.Query // Previous stores, if any, previous entity information (mainly for update) Previous interface{} // Payload stores, if any, current request payload information Payload interface{} }
Request contains all common fields needed for a usual API request
type RouterFunc ¶
RouterFunc generalize router to route an http.Handler
type Service ¶
type Service struct { Path string Methods []string Weight int Context context.Context Middlewares *Middlewares Endpoint endpoint.Endpoint DecodeFunc httptransport.DecodeRequestFunc EncodeFunc httptransport.EncodeResponseFunc Before []httptransport.RequestFunc After []httptransport.ServerResponseFunc ErrorEncoder httptransport.ErrorEncoder Options []httptransport.ServerOption }
Service contains all parameters needed to call httptransport.NewServer
func NewJSONService ¶
NewJSONService creates a service descriptor with defaults for a simple JSON service
func (Service) Route ¶
func (s Service) Route(rtr RouterFunc) error
Route add the given service to router with RouterFunc
type ServiceSlice ¶
type ServiceSlice []*Service
ServiceSlice attaches the method of sort.Interface to []*Service, sort in increasing order
func (ServiceSlice) Less ¶
func (ss ServiceSlice) Less(i, j int) bool
Less implements sort.Interface
func (ServiceSlice) Sort ¶
func (ss ServiceSlice) Sort()
Sort is a short hand for sort.Sort(ServiceSlice)
type Services ¶
Services contain a group of named services
func (Services) Patch ¶
func (services Services) Patch(patches ...ServicesPatch)
Patch takes a patch / patches and apply them to the group
func (Services) Route ¶
func (services Services) Route(rtr RouterFunc) (err error)
Route routes all services in the group
type ServicesPatch ¶
ServicesPatch patches all children in a map[string]*Service