Documentation ¶
Overview ¶
Package tree implements the main objects and methods for JSONrouter.
Index ¶
- type Config
- func (config *Config) ForceTLS()
- func (config *Config) MetricsHandler(req http.Request) *http.Status
- func (config *Config) NoCache()
- func (config *Config) RecordMetrics()
- func (config *Config) SpecHandler(req http.Request) *http.Status
- func (config *Config) SpecV2() *openapiv2.Spec
- func (config *Config) SpecV3() *openapiv3.Spec
- type File
- type Handler
- func (handler *Handler) Description(descr string) *Handler
- func (handler *Handler) DetectContentType(req http.Request, filePath string) *http.Status
- func (handler *Handler) Optional(objects ...validation.Payload) *Handler
- func (handler *Handler) Path(removePrefix ...string) string
- func (handler *Handler) ReadHeaderPayload(req http.Request) *http.Status
- func (handler *Handler) ReadPayload(req http.Request) *http.Status
- func (handler *Handler) Ref(basePath string) string
- func (handler *Handler) Required(objects ...validation.Payload) *Handler
- func (handler *Handler) RequiredHeaders(headers ...validation.Payload) *Handler
- func (handler *Handler) Response(schema ...interface{}) *Handler
- func (handler *Handler) Security(sec security.SecurityModule) *Handler
- func (handler *Handler) UpdateSpec() *Handler
- func (handler *Handler) UseFunction(f interface{})
- type HandlerFunction
- type Module
- type ModuleFunction
- type Node
- func (node *Node) Add(path string, pathKeys ...string) *Node
- func (node *Node) DELETE(functions ...interface{}) *Handler
- func (node *Node) File(path string) *Node
- func (node *Node) Folder(directoryPath string, filters ...string) *Node
- func (node *Node) FullPath() string
- func (node *Node) GET(functions ...interface{}) *Handler
- func (node *Node) GetHeaders() map[string]interface{}
- func (node *Node) HEAD(functions ...interface{}) *Handler
- func (node *Node) Handler(req http.Request) *Handler
- func (node *Node) Init(function ModuleFunction, arg interface{}) *Node
- func (node *Node) Mod(function ModuleFunction, arg interface{}) *Node
- func (node *Node) Next(req http.Request, pathSegment string) (*Node, *http.Status)
- func (node *Node) PATCH(functions ...interface{}) *Handler
- func (node *Node) POST(functions ...interface{}) *Handler
- func (node *Node) PUT(functions ...interface{}) *Handler
- func (node *Node) Param(vc *validation.Config, keys ...string) *Node
- func (node *Node) RunModule(req http.Request) *http.Status
- func (node *Node) RunModules(req http.Request) *http.Status
- func (node *Node) Security(module security.SecurityModule) *Node
- func (node *Node) SetHeaders(headers map[string]interface{}) *Node
- func (node *Node) StaticFolder(directoryPath string, filters ...string) *Node
- func (node *Node) Use(newNode *Node)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Log logging.Logger Spec interface{} // ProjectName is for App Engine apps ServiceName string ProjectName string CacheFiles bool ForcedTLS bool UseMetrics bool MetResults map[string]interface{} Metrics metrics.Metrics sync.RWMutex }
func (*Config) MetricsHandler ¶
MetricsHandler serves the raw metrics to a HTTP request.
func (*Config) NoCache ¶
func (config *Config) NoCache()
NoCache sets the no-cache part of the router config to true. This stops any static files being cached.
func (*Config) RecordMetrics ¶
func (config *Config) RecordMetrics()
MetricsHandler serves the raw metrics to a HTTP request.
func (*Config) SpecHandler ¶
SpecHandler serves the raw spec to a HTTP request.
type Handler ¶
type Handler struct { Node *Node Method string Descr string Function func(req http.Request) *http.Status File *File SecurityModule security.SecurityModule sync.RWMutex // contains filtered or unexported fields }
func (*Handler) Description ¶
Description describes the function via the spec JSON
func (*Handler) DetectContentType ¶
func (*Handler) Optional ¶
func (handler *Handler) Optional(objects ...validation.Payload) *Handler
Optional applies model which describes optional request payload fields
func (*Handler) ReadHeaderPayload ¶
ReadPayload validates any payload present in the request body, according to the payloadSchema
func (*Handler) ReadPayload ¶
ReadPayload validates any payload present in the request body, according to the payloadSchema
func (*Handler) Required ¶
func (handler *Handler) Required(objects ...validation.Payload) *Handler
Required applies model which describes required request payload fields
func (*Handler) RequiredHeaders ¶
func (handler *Handler) RequiredHeaders(headers ...validation.Payload) *Handler
SetHeaders allows the headers for the HTTP response to be set by providing a map of header key, values.
func (*Handler) UpdateSpec ¶
UpdateSpec pushed updates into the spec object
func (*Handler) UseFunction ¶
func (handler *Handler) UseFunction(f interface{})
type Node ¶
type Node struct { Config *Config Parent *Node Path string Parameter *Node Routes map[string]*Node Methods map[string]*Handler Module *Module Modules []*Module SecurityModule security.SecurityModule Validation *validation.Config Validations []*validation.Config sync.RWMutex // contains filtered or unexported fields }
func (*Node) Folder ¶
Folder walks through the specified folder to mirror the file structure for files containing all filters
func (*Node) GetHeaders ¶
func (*Node) Init ¶
func (node *Node) Init(function ModuleFunction, arg interface{}) *Node
Init adds a module that will be executed at the point it is added to the route
func (*Node) Mod ¶
func (node *Node) Mod(function ModuleFunction, arg interface{}) *Node
Mod adds a module that will be executed upon reaching a handler
func (*Node) Param ¶
func (node *Node) Param(vc *validation.Config, keys ...string) *Node
Param adds a new param-node
func (*Node) RunModules ¶
RunModules executes all module functions added with .Mod(...)
func (*Node) SetHeaders ¶
func (*Node) StaticFolder ¶
StaticFolder walks through the specified folder to mirror the file structure for files containing all filters