route

package
v0.0.0-...-33b106d Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagInfo = "_info" // describes the REST API usage

	TagHeaderName = "X-LIREST-TAG" // the HTTP tag used for the tag

)

URL that starts with underscore are special tags tags supported: _info: describs the REST info for this url

Variables

This section is empty.

Functions

func GenerateCommandRoutes

func GenerateCommandRoutes(r *mux.Router) error

GenerateCommandRoutes produces routes based on commandRoutes

func JsonpMiddleware

func JsonpMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

JsonpMiddleware wraps the json output with callback function name

func LogMiddleware

func LogMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

LogMiddleware logs access

func NewRouter

func NewRouter(t *Trie) http.Handler

NewRouter creates a router defined hierarchically starting from the top level

func TagMiddleware

func TagMiddleware(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

TagMiddleware handles the special tags

Types

type DelHandler

type DelHandler func(map[string]string) error

DelHandler responds to "DELETE"

type GetHandler

type GetHandler func(map[string]string) interface{}

GetHandler responds to "GET"

type NewHandler

type NewHandler func(map[string]string) error

NewHandler responds to "POST"

type PathHandler

type PathHandler struct {
	SubPath []string
}

PathHandler contains slice of next level subpath

func (*PathHandler) ServeHTTP

func (h *PathHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP the HTTP handler

type ResourceHandler

type ResourceHandler struct {
	Name   string
	System describe.DescriptionSystem
	Api    describe.DescriptionApi
}

ResourceHandler Describe a resource handler

func (*ResourceHandler) ServeHTTP

func (h *ResourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP ResourceHandler's HTTP handler function

type SetHandler

type SetHandler func(map[string]string, interface{}) error

SetHandler responds to "PUT"

type Trie

type Trie struct {
	Val   interface{}
	Nodes map[string]*Trie
}

Trie is a data structure to keep the route relationships this is created from the descriptions and used to create routes

func NewTrie

func NewTrie() *Trie

NewTrie create the trie root

func (*Trie) AddPath

func (t *Trie) AddPath(path string, val interface{}) error

AddPath add a path to the Trie a path contains slash separated strings such as /a/b/c/d/e

func (*Trie) Count

func (t *Trie) Count() int

Count counts the number of nodes in the trie

func (*Trie) Depth

func (t *Trie) Depth() int

Depthfind the depth of the trie

Jump to

Keyboard shortcuts

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