Documentation ¶
Overview ¶
Package handlerfactory allows creating HTTP handlers for services.
Index ¶
- func MakeHandler(s storage.Store, opts *Options) http.HandlerFunc
- func Process(s storage.Store, opts *Options, r *http.Request) (_ proto.Message, ferr error)
- func RunRMWTx(r *http.Request, tx storage.Tx, ...) (proto.Message, error)
- func ValidateResourceName(r *http.Request, field string, nameRE map[string]*regexp.Regexp) (string, map[string]string, error)
- type Empty
- func (s *Empty) CheckIntegrity(r *http.Request) *status.Status
- func (s *Empty) Get(r *http.Request, name string) (proto.Message, error)
- func (s *Empty) LookupItem(r *http.Request, name string, vars map[string]string) bool
- func (s *Empty) NormalizeInput(r *http.Request, name string, vars map[string]string) error
- func (s *Empty) Patch(r *http.Request, name string) (proto.Message, error)
- func (s *Empty) Post(r *http.Request, name string) (proto.Message, error)
- func (s *Empty) Put(r *http.Request, name string) (proto.Message, error)
- func (s *Empty) Remove(r *http.Request, name string) (proto.Message, error)
- func (s *Empty) Save(r *http.Request, tx storage.Tx, name string, vars map[string]string, ...) error
- func (s *Empty) Setup(r *http.Request, tx storage.Tx) (int, error)
- type Options
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeHandler ¶
func MakeHandler(s storage.Store, opts *Options) http.HandlerFunc
MakeHandler created a HTTP handler wrapper around a given service.
func RunRMWTx ¶
func RunRMWTx( r *http.Request, tx storage.Tx, op func(*http.Request, string) (proto.Message, error), check func(*http.Request) *status.Status, save func(*http.Request, storage.Tx, string, map[string]string, string, string) error, name string, vars map[string]string, typ string, desc string, ) (proto.Message, error)
RunRMWTx performs a RMW operation. Saves the transaction after performing integraty check. Rolls back the transaction on any failure. TODO: move outside this package. Service handlers should call it.
Types ¶
type Empty ¶ added in v0.8.9
type Empty struct { }
Empty is a empty Service implementation for mixin.
func (*Empty) CheckIntegrity ¶ added in v0.8.9
CheckIntegrity empty impl
func (*Empty) LookupItem ¶ added in v0.8.9
LookupItem empty impl
func (*Empty) NormalizeInput ¶ added in v0.8.9
NormalizeInput empty impl
type Options ¶ added in v0.8.6
type Options struct { TypeName string NameField string PathPrefix string HasNamedIdentifiers bool NameChecker map[string]*regexp.Regexp Service func() Service }
Options contains the information about a handler service. Essentially the service interface + some options to the HTTP wrapper for it.
type Service ¶ added in v0.8.6
type Service interface { Setup(r *http.Request, tx storage.Tx) (int, error) // TODO: Have LookupItem() return an error instead, so different errors can be handled // properly, e.g. permission denied error vs. lookup error. LookupItem(r *http.Request, name string, vars map[string]string) bool NormalizeInput(r *http.Request, name string, vars map[string]string) error Get(r *http.Request, name string) (proto.Message, error) Post(r *http.Request, name string) (proto.Message, error) Put(r *http.Request, name string) (proto.Message, error) Patch(r *http.Request, name string) (proto.Message, error) Remove(r *http.Request, name string) (proto.Message, error) CheckIntegrity(r *http.Request) *status.Status Save(r *http.Request, tx storage.Tx, name string, vars map[string]string, desc, typeName string) error }
Service is the role interface for a service that will be wrapped.