common

package
v0.0.0-...-3a6b306 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ROBOTS_TXT = "User-agent: *\nDisallow: /api/"
)

Variables

This section is empty.

Functions

func Respond

func Respond(req web.RequestInterface, status *web.ResponseStatus) error

Types

type Array

type Array []interface{}

type Config

type Config struct {
	Spec *openapi.APISpec
	Log  logging.Logger
	// ProjectName is for App Engine apps
	ProjectName    string
	RootRegistry   Registry
	SubdomainTrees map[string]*Node

	Handlers []*Handler

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Config) BuildOpenAPISpec

func (config *Config) BuildOpenAPISpec(req web.RequestInterface) *openapi.APISpec

Builds the handler documentation object.

func (*Config) ForceTLS

func (config *Config) ForceTLS()

block all non-https requests

func (*Config) GetRootFunction

func (config *Config) GetRootFunction(functionKey string) func(req web.RequestInterface) *web.ResponseStatus

Returns the root function if present in the registry

func (*Config) NoCache

func (config *Config) NoCache()

func (*Config) SetDelims

func (config *Config) SetDelims(l, r string)

func (*Config) SetHeaders

func (config *Config) SetHeaders(h Headers)

Sets the http preflight headers to the specified map

func (*Config) SetRootRegistry

func (config *Config) SetRootRegistry(reg Registry)

Sets the root registry to the specified map

func (*Config) SubTree

func (config *Config) SubTree(subdomain string) *Node

type Handler

type Handler struct {
	Config      *Config
	Node        *Node
	Method      string
	Description string

	IsFile bool

	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Handler) ApiUrl

func (handler *Handler) ApiUrl() string

func (*Handler) Body

func (handler *Handler) Body(objects ...*Payload) *Handler

Applies model which describes request payload

func (*Handler) BodyIsArray

func (handler *Handler) BodyIsArray() *Handler

Applies model which describes request payload

func (*Handler) BodyIsObject

func (handler *Handler) BodyIsObject() *Handler

Applies model which describes request payload

func (*Handler) Describe

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

Describes the function via the spec JSON

func (*Handler) DetectContentType

func (handler *Handler) DetectContentType(req web.RequestInterface, filePath string) *web.ResponseStatus

func (*Handler) OptionalBody

func (handler *Handler) OptionalBody(obj *Optional) *Handler

Applies model which describes request payload

func (*Handler) Patch

func (handler *Handler) Patch(objects ...*Patch) *Handler

Applies model which describes request payload

func (*Handler) ReadPayload

func (handler *Handler) ReadPayload(req web.RequestInterface) *web.ResponseStatus

Validates any payload present in the request body, according to the payloadSchema

func (*Handler) Response

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

Applys model which describes response schema

func (*Handler) Spec

func (handler *Handler) Spec(req web.RequestInterface) *HandlerSpec

func (*Handler) UseFunction

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

type HandlerArray

type HandlerArray []*HandlerSpec

func (HandlerArray) Len

func (a HandlerArray) Len() int

func (HandlerArray) Less

func (a HandlerArray) Less(x, y int) bool

func (HandlerArray) Swap

func (a HandlerArray) Swap(x, y int)

type HandlerSpec

type HandlerSpec struct {
	Method                string                        `json:"method"`
	Endpoint              string                        `json:"endpoint"`
	MockEndpoint          string                        `json:"mockEndpoint"`
	MockPayload           interface{}                   `json:"mockPayload,omitempty"`
	PayloadSchema         interface{}                   `json:"payloadSchema,omitempty"`
	OptionalPayloadSchema interface{}                   `json:"optionalPayloadSchema,omitempty"`
	ResponseSchema        interface{}                   `json:"responseSchema,omitempty"`
	RouteParams           map[string]*validation.Config `json:"routeParams,omitempty"`
	IsFile                bool                          `json:"isFile"`
	FilePath              string                        `json:"filePath,omitempty"`
	Description           string                        `json:"description,omitempty"`
}

func (*HandlerSpec) NewMockPath

func (spec *HandlerSpec) NewMockPath(patches ...map[string]interface{})

func (*HandlerSpec) NewMockPayload

func (spec *HandlerSpec) NewMockPayload(patches ...map[string]interface{})

type Headers

type Headers map[string]string

type Middleware

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

func (*Middleware) Run

type MiddlewareFunction

type MiddlewareFunction func(*Middleware, web.RequestInterface, interface{}) *web.ResponseStatus

type Module

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

func (*Module) Run

func (mod *Module) Run(req web.RequestInterface) *web.ResponseStatus

type ModuleFunction

type ModuleFunction func(web.RequestInterface, interface{}) *web.ResponseStatus

type ModuleRegistry

type ModuleRegistry map[string]ModuleFunction

type Node

type Node struct {
	Config *Config

	Validation  *validation.Config
	Validations []*validation.Config
	sync.RWMutex
	// contains filtered or unexported fields
}

func Root

func Root() *Node

func (*Node) Add

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

Adds a new node to the tree

func (*Node) AuthBearer

func (node *Node) AuthBearer() *Node

Adds a new param-node

func (*Node) DELETE

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

Allows POST requests to the node's handler

func (*Node) File

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

Adds a file to be served from the specified path.

func (*Node) Folder

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

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

func (*Node) FullPath

func (node *Node) FullPath() string

Returns the node's full path string

func (*Node) GET

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

Allows GET requests to the node's handler

func (*Node) HEAD

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

Allows POST requests to the node's handler

func (*Node) Init

func (node *Node) Init(function ModuleFunction, arg interface{}) *Node

Adds a module that will be executed at the point it is added to the route

func (*Node) MainHandler

func (node *Node) MainHandler(req web.RequestInterface, fullPath string) (status *web.ResponseStatus)

main handler

func (*Node) Mid

func (node *Node) Mid(function MiddlewareFunction, arg interface{}) *Node

Adds a module that will be executed upon reaching a handler

func (*Node) Mod

func (node *Node) Mod(function ModuleFunction, arg interface{}) *Node

Adds a module that will be executed upon reaching a handler

func (*Node) Next

func (node *Node) Next(req web.RequestInterface, pathSegment string) (*Node, *web.ResponseStatus)

finds next node according to supplied URL path segment

func (*Node) PATCH

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

Allows POST requests to the node's handler

func (*Node) POST

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

Allows POST requests to the node's handler

func (*Node) PUT

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

Allows PUT requests to the node's handler

func (*Node) Param

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

Adds a new param-node

func (*Node) Path

func (node *Node) Path() string

Returns the node's path string

func (*Node) RequestParams

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

returns the base param map including node params

func (*Node) RunModule

func (node *Node) RunModule(req web.RequestInterface) *web.ResponseStatus

execute init function added with .Init(...)

func (*Node) RunModules

func (node *Node) RunModules(req web.RequestInterface) *web.ResponseStatus

execute all module functions added with .Mod(...)

func (*Node) StaticFolder

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

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

type Object

type Object map[string]interface{}

type Optional

type Optional map[string]*validation.Config

type Patch

type Patch map[string]*validation.Config

type Payload

type Payload map[string]*validation.Config

func (Payload) WithFields

func (payload Payload) WithFields(fields Payload) Payload

type Registry

type Registry map[string]func(req web.RequestInterface) *web.ResponseStatus

type Router

type Router interface {
	Serve(int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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