Documentation
¶
Index ¶
- type Authorizer
- type Context
- type Endpoint
- type Endpointer
- type Error
- type Handler
- type Inputer
- type Logger
- type Paramer
- type PermissionManager
- type RequestDebugger
- type Resulter
- type TokenDecoder
- type TokenPayloader
- type Tokener
- type Vatel
- func (v *Vatel) Add(cs Endpointer)
- func (v *Vatel) BuildHandlers(mux *router.Router, l *zerolog.Logger) error
- func (v *Vatel) DisableAuthorizer()
- func (v *Vatel) Endpoints() []Endpoint
- func (v *Vatel) MustBuildHandlers(mux *router.Router, l *zerolog.Logger)
- func (v *Vatel) Set(key, value string)
- func (v *Vatel) SetAuthorizer(a Authorizer)
- func (v *Vatel) SetPermissionManager(pm PermissionManager)
- func (v *Vatel) SetRequestDebugger(rd RequestDebugger)
- func (v *Vatel) SetTokenDecoder(tp TokenDecoder)
- type VatelContext
- func (ctx *VatelContext) BodyWriter() io.Writer
- func (ctx *VatelContext) FormFile(key string) (*multipart.FileHeader, error)
- func (ctx *VatelContext) FormValue(key string) []byte
- func (ctx *VatelContext) Header(name string) []byte
- func (ctx *VatelContext) Log(key string, val interface{}) *VatelContext
- func (ctx *VatelContext) LogValues() map[string]interface{}
- func (ctx *VatelContext) SaveMultipartFile(fh *multipart.FileHeader, path string) error
- func (ctx *VatelContext) SetContentType(contentType []byte) *VatelContext
- func (ctx *VatelContext) SetHeader(name, val []byte) *VatelContext
- func (ctx *VatelContext) SetStatusCode(code int) *VatelContext
- func (ctx *VatelContext) SetTokenPayload(tp TokenPayloader)
- func (ctx *VatelContext) TokenPayload() TokenPayloader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
Authorizer is the interface that wraps IsAllowed method.
Authorizer accepts request permissions and permissions required by endpoint. Returns true if all endpointPerms are inside requestPerms.
type Context ¶
type Context interface {
BodyWriter() io.Writer
SetContentType([]byte) *VatelContext
Log(key string, val interface{}) *VatelContext
LogValues() map[string]interface{}
SetStatusCode(code int) *VatelContext
FormFile(key string) (*multipart.FileHeader, error)
FormValue(key string) []byte
SaveMultipartFile(fh *multipart.FileHeader, path string) error
Header(name string) []byte
TokenPayload() TokenPayloader
SetTokenPayload(tp TokenPayloader)
SetHeader(name, val []byte) *VatelContext
}
func NewContext ¶
func NewContext(ctx *fasthttp.RequestCtx) Context
type Endpoint ¶
type Endpoint struct {
// Method holds HTTP method name (e.g GET, POST, PUT, DELETE).
Method string
// Path holds url path with fasthttp parameters (e.g. /customers/{id}).
Path string
// Perms holds list of permissions. Nil if endpoint is public.
Perms []string
// Controller holds reference to the object impementing interface Handler.
Controller func() Handler
// ResponseContentType by default has "application/json; charset: utf-8;"
ResponseContentType string
// NoInputLog defines debug logging rule for request data. If true, endpoint request body
// will not be written to the log. (i.e authentication endpoint).
NoInputLog bool
// NoResultLog defines debug logging rule for response data. If true, endpoint response body
// will not be written to the log. (i.e authentication endpoint)
NoResultLog bool
LanguageLabel string // #Cannon
// contains filtered or unexported fields
}
Endpoint describes a REST endpoint attributes and related request Handler.
type Endpointer ¶
type Endpointer interface {
Endpoints() []Endpoint
}
Endpointer is the interface that wraps a single Endpoints method.
Endpoints returns []Endpoints to be handled by API gateway.
type Error ¶
type Error struct {
errors.CatchedError
}
Error overloading for zerolog.Implementation
func (*Error) MarshalZerologObject ¶
type Handler ¶
Handler is the interface what wraps Handle method.
Handle invocates by API gateway mux.
type Inputer ¶
type Inputer interface {
Input() interface{}
}
Inputer is the interface what wraps Input method.
Input returns reference to the object what will be promoted with input data by vatel.
If endpoint's handler expects input data, Input method should be implemented.
GET, DELETE methods: input values will be taken from URL query. POST, PUT, PATCH methods: input values will be taken from JSON body.
type Paramer ¶
type Paramer interface {
Param() interface{}
}
Paramer is the interface what wraps a single Param method.
Param returns reference to the struct what will be promoted with values from URL.
Example: if we have /customer/{id}/bill/{billnum} then Param() should return reference to struct
{
CustomerID int `param:"id"
BillNum string `param:"billnum"`
}
type PermissionManager ¶
PermissionManager ...
type RequestDebugger ¶
type RequestDebugger interface {
IsDebugRequired(TokenPayloader) (in, out bool)
}
type Resulter ¶
type Resulter interface {
Result() interface{}
}
Resulter is the interface what wraps Result method.
Result returns reference to the object what will be send to the client when endpoint handler completes succesfully.
If endpoint's controller have outgoing data, Result method should be implemented.
type TokenDecoder ¶
TokenDecoder is the interface what wraps a single method Decode.
TokenDecoder decodes token and returns object Tokener.
type TokenPayloader ¶
type TokenPayloader interface {
User() int
Login() string
Role() int
Perms() []byte
Extra() interface{}
}
TokenPayloader is the interface that wraps access methods to JWT payload parts.
User returns value of user attribute from the token.
Perms returns bitset array with user role's permissions.
type Tokener ¶
type Tokener interface {
SystemPayload() map[string]interface{}
ApplicationPayload() TokenPayloader
}
Tokener is the interface that wraps methods SystemPayload and UserPayload.
SystemPayload returns JWT part related to JWT itself.
UserPayload returns an object that represents JWT payload specified by user.
type Vatel ¶
type Vatel struct {
// contains filtered or unexported fields
}
Vatel holds
func (*Vatel) Add ¶
func (v *Vatel) Add(cs Endpointer)
Add add endpoints to the list.
The method does not check Endpoint for correctes and uqiqueness here. Paths validation implemented by method BuildHandlers.
func (*Vatel) BuildHandlers ¶
BuildHandlers initializes http muxer with rules by converting []Endpoint added before.
func (*Vatel) DisableAuthorizer ¶
func (v *Vatel) DisableAuthorizer()
func (*Vatel) MustBuildHandlers ¶
MustBuildHandlers initializes http muxer with rules by converting []Endpoint added before. Panics if:
- there are Perms but SetAuthorizer or SetTokenDecoder were not called. -
func (*Vatel) SetAuthorizer ¶
func (v *Vatel) SetAuthorizer(a Authorizer)
SetAuthorizer assigns authorization implementation. If Authorizer is not assigned, all Endpoint's Perms will be ignored.
func (*Vatel) SetPermissionManager ¶
func (v *Vatel) SetPermissionManager(pm PermissionManager)
SetPermissionManager assigns permission manager implementation.
func (*Vatel) SetRequestDebugger ¶
func (v *Vatel) SetRequestDebugger(rd RequestDebugger)
SetRequestDebugger assigns request debugger implementation.
func (*Vatel) SetTokenDecoder ¶
func (v *Vatel) SetTokenDecoder(tp TokenDecoder)
SetTokenDecoder assigns session token decoder.
type VatelContext ¶
func (*VatelContext) BodyWriter ¶
func (ctx *VatelContext) BodyWriter() io.Writer
func (*VatelContext) FormFile ¶
func (ctx *VatelContext) FormFile(key string) (*multipart.FileHeader, error)
func (*VatelContext) FormValue ¶
func (ctx *VatelContext) FormValue(key string) []byte
func (*VatelContext) Header ¶
func (ctx *VatelContext) Header(name string) []byte
func (*VatelContext) Log ¶
func (ctx *VatelContext) Log(key string, val interface{}) *VatelContext
func (*VatelContext) LogValues ¶
func (ctx *VatelContext) LogValues() map[string]interface{}
func (*VatelContext) SaveMultipartFile ¶
func (ctx *VatelContext) SaveMultipartFile(fh *multipart.FileHeader, path string) error
func (*VatelContext) SetContentType ¶
func (ctx *VatelContext) SetContentType(contentType []byte) *VatelContext
func (*VatelContext) SetHeader ¶
func (ctx *VatelContext) SetHeader(name, val []byte) *VatelContext
func (*VatelContext) SetStatusCode ¶
func (ctx *VatelContext) SetStatusCode(code int) *VatelContext
func (*VatelContext) SetTokenPayload ¶
func (ctx *VatelContext) SetTokenPayload(tp TokenPayloader)
func (*VatelContext) TokenPayload ¶
func (ctx *VatelContext) TokenPayload() TokenPayloader