router

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2019 License: MIT Imports: 4 Imported by: 1

README

Router ... wrapper for http standard library, does parameters too...

Documentation

Index

Constants

View Source
const (
	//GET ...
	GET = "GET"
	//POST ...
	POST = "POST"
	//PUT ...
	PUT = "PUT"
	//DELETE ...
	DELETE = "DELETE"
	//PATCH ...
	PATCH = "PATCH"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(w http.ResponseWriter, r *http.Request, p map[string]string)

Handler ... defines a parameterized handler within server

type Result

type Result struct {
	Handler Handler
	Method  string
	Parms   map[string]string
	Status  int
}

Result ... stores a router result

func NewResult

func NewResult() (result *Result)

NewResult creates a new result object

type Route

type Route struct {
	ID         string
	Children   map[string]*Route
	Handler    map[string]Handler
	Parameters map[string]string
	Method     string
}

Route holds a route, it's parameters, in a tree

func NewRoute

func NewRoute(ID string) (route *Route)

NewRoute ...

func (*Route) Add

func (route *Route) Add(ID string) (_route *Route)

Add ... adds a node to the Nodes map

func (*Route) Get

func (route *Route) Get(ID string) (_route *Route, err error)

Get ... gets a node

type Router

type Router struct {
	Port string
	Log  *log.Log
	// contains filtered or unexported fields
}

Router object contains routes

func New

func New(_log *log.Log) (router *Router, err error)

New creates a new router object

func (*Router) Delete

func (router *Router) Delete(path string, handler Handler) (err error)

Delete ... creates a Delete endpoint

func (*Router) Get

func (router *Router) Get(path string, handler Handler) (err error)

Get ... creates a Get endpoint

func (*Router) Patch

func (router *Router) Patch(path string, handler Handler) (err error)

Patch ... creates a Patch endpoint

func (*Router) Post

func (router *Router) Post(path string, handler Handler) (err error)

Post ... creates a Post endpoint

func (*Router) Put

func (router *Router) Put(path string, handler Handler) (err error)

Put ... creates a Put endpoint

func (*Router) Search

func (router *Router) Search(path string, method string) (_result *Result, err error)

Search ... searches a route

func (*Router) ServeHTTP

func (router *Router) ServeHTTP(res http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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