tree

package
v0.0.0-...-1676a5e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tree implements the main objects and methods for JSONrouter.

Index

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) ForceTLS

func (config *Config) ForceTLS()

ForceTLS blocks all non-https requests

func (*Config) MetricsHandler

func (config *Config) MetricsHandler(req http.Request) *http.Status

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

func (config *Config) SpecHandler(req http.Request) *http.Status

SpecHandler serves the raw spec to a HTTP request.

func (*Config) SpecV2

func (config *Config) SpecV2() *openapiv2.Spec

SpecV2 exposes the spec object as a V2

func (*Config) SpecV3

func (config *Config) SpecV3() *openapiv3.Spec

SpecV3 exposes the spec object as a V3

type File

type File struct {
	Path     string
	MimeType string
	Cache    []byte
	sync.RWMutex
}

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

func (handler *Handler) Description(descr string) *Handler

Description describes the function via the spec JSON

func (*Handler) DetectContentType

func (handler *Handler) DetectContentType(req http.Request, filePath string) *http.Status

func (*Handler) Optional

func (handler *Handler) Optional(objects ...validation.Payload) *Handler

Optional applies model which describes optional request payload fields

func (*Handler) Path

func (handler *Handler) Path(removePrefix ...string) string

func (*Handler) ReadHeaderPayload

func (handler *Handler) ReadHeaderPayload(req http.Request) *http.Status

ReadPayload validates any payload present in the request body, according to the payloadSchema

func (*Handler) ReadPayload

func (handler *Handler) ReadPayload(req http.Request) *http.Status

ReadPayload validates any payload present in the request body, according to the payloadSchema

func (*Handler) Ref

func (handler *Handler) Ref(basePath string) string

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) Response

func (handler *Handler) Response(schema ...interface{}) *Handler

Response applies model which describes response schema

func (*Handler) Security

func (handler *Handler) Security(sec security.SecurityModule) *Handler

func (*Handler) UpdateSpec

func (handler *Handler) UpdateSpec() *Handler

UpdateSpec pushed updates into the spec object

func (*Handler) UseFunction

func (handler *Handler) UseFunction(f interface{})

type HandlerFunction

type HandlerFunction func(req http.Request) *http.Status

type Module

type Module struct {
	// contains filtered or unexported fields
}

func (*Module) Run

func (mod *Module) Run(req http.Request) *http.Status

Run will run the module function

type ModuleFunction

type ModuleFunction func(req http.Request, arg interface{}) *http.Status

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 NewNode

func NewNode(config *Config) *Node

func (*Node) Add

func (node *Node) Add(path string, pathKeys ...string) *Node

Add adds a new node to the tree

func (*Node) DELETE

func (node *Node) DELETE(functions ...interface{}) *Handler

DELETE allows DELETE requests to the node's handler

func (*Node) File

func (node *Node) File(path string) *Node

File adds a file to be served from the specified path.

func (*Node) Folder

func (node *Node) Folder(directoryPath string, filters ...string) *Node

Folder walks through the specified folder to mirror the file structure for files containing all filters

func (*Node) FullPath

func (node *Node) FullPath() string

FullPath returns the node's full path string

func (*Node) GET

func (node *Node) GET(functions ...interface{}) *Handler

GET allows GET requests to the node's handler

func (*Node) GetHeaders

func (node *Node) GetHeaders() map[string]interface{}

func (*Node) HEAD

func (node *Node) HEAD(functions ...interface{}) *Handler

HEAD allows POST requests to the node's handler

func (*Node) Handler

func (node *Node) Handler(req http.Request) *Handler

Handler returns the handler assciated with the HTTP request method.

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) Next

func (node *Node) Next(req http.Request, pathSegment string) (*Node, *http.Status)

Next finds next node according to supplied URL path segment

func (*Node) PATCH

func (node *Node) PATCH(functions ...interface{}) *Handler

PATCH allows PATCH requests to the node's handler

func (*Node) POST

func (node *Node) POST(functions ...interface{}) *Handler

POST allows POST requests to the node's handler

func (*Node) PUT

func (node *Node) PUT(functions ...interface{}) *Handler

PUT allows PUT requests to the node's handler

func (*Node) Param

func (node *Node) Param(vc *validation.Config, keys ...string) *Node

Param adds a new param-node

func (*Node) RunModule

func (node *Node) RunModule(req http.Request) *http.Status

RunModule executes init function added with .Init(...)

func (*Node) RunModules

func (node *Node) RunModules(req http.Request) *http.Status

RunModules executes all module functions added with .Mod(...)

func (*Node) Security

func (node *Node) Security(module security.SecurityModule) *Node

func (*Node) SetHeaders

func (node *Node) SetHeaders(headers map[string]interface{}) *Node

func (*Node) StaticFolder

func (node *Node) StaticFolder(directoryPath string, filters ...string) *Node

StaticFolder walks through the specified folder to mirror the file structure for files containing all filters

func (*Node) Use

func (node *Node) Use(newNode *Node)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL