ts

package module
v0.0.0-...-2cfd725 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

ysnet

Documentation

Overview

* https://github.com/xujiajun/gorouter.git

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGenerateParameters is returned when generating a route with wrong parameters.
	ErrGenerateParameters = errors.New("params contains wrong parameters")

	// ErrNotFoundRoute is returned when generating a route that can not find route in tree.
	ErrNotFoundRoute = errors.New("cannot find route in tree")

	// ErrNotFoundMethod is returned when generating a route that can not find method in tree.
	ErrNotFoundMethod = errors.New("cannot find method in tree")

	// ErrPatternGrammar is returned when generating a route that pattern grammar error.
	ErrPatternGrammar = errors.New("pattern grammar error")
)
View Source
var (
	MULTI_FORM = "multipart/form-data"
)

Functions

func GetAllParams

func GetAllParams(r *http.Request) paramsMapType

GetAllParams returns all route params stored in http.Request.

func GetParam

func GetParam(r *http.Request, key string) string

GetParam returns route param stored in http.request.

Types

type App

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

func NewApp

func NewApp() *App

func (*App) Group

func (e *App) Group(group string) *RouterGroup

func (*App) Router

func (e *App) Router() *RouterGroup

func (*App) ServeFile

func (e *App) ServeFile(ctx *Context, path string)

func (*App) ServeFiles

func (e *App) ServeFiles(fileServer http.Handler, ctx *Context)

func (*App) ServeHTTP

func (e *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Context

type Context struct {
	Req    *http.Request
	Params Params
	// contains filtered or unexported fields
}

func (*Context) AsciiJSON

func (c *Context) AsciiJSON(code int, obj interface{})

AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. It also sets the Content-Type as "application/json".

func (*Context) BindJSON

func (c *Context) BindJSON(obj interface{}) error

func (*Context) Form

func (c *Context) Form(name string) string

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".

func (*Context) Path

func (c *Context) Path(name string) string

func (*Context) PureJSON

func (c *Context) PureJSON(code int, obj interface{})

PureJSON serializes the given struct as JSON into the response body. PureJSON, unlike JSON, does not replace special html characters with their unicode entities.

func (*Context) Query

func (c *Context) Query(name string) string

func (*Context) Render

func (c *Context) Render(code int, r render.Render)

func (*Context) ShouldBindWith

func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error

bing

func (*Context) Status

func (c *Context) Status(code int)

Status sets the HTTP response code.

func (*Context) Text

func (c *Context) Text(code int, format string, args ...interface{})

type HandleFunc

type HandleFunc func(ctx *Context)

type MiddlewareType

type MiddlewareType func(next http.HandlerFunc) http.HandlerFunc

MiddlewareType is a public type that is used for middleware

type Node

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

Node records any URL params, and executes an end handler.

func NewNode

func NewNode(key string, depth int) *Node

NewNode returns a newly initialized Node object that implements the Node

type Param

type Param struct {
	Key   string
	Value string
}

type Parameters

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

Parameters records some parameters

type Params

type Params []Param

type ResponeWriter

type ResponeWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ResponeWriter) Size

func (w *ResponeWriter) Size() int

func (*ResponeWriter) Status

func (w *ResponeWriter) Status() int

func (*ResponeWriter) WriteHeaderNow

func (w *ResponeWriter) WriteHeaderNow(code int)

func (*ResponeWriter) Written

func (w *ResponeWriter) Written() bool

type Router

type Router struct {

	// PanicHandler for handling panic.
	PanicHandler func(w http.ResponseWriter, req *http.Request, err interface{})
	// contains filtered or unexported fields
}

Router is a simple HTTP route multiplexer that parses a request path, records any URL params, and executes an end handler.

func NewRouter

func NewRouter() *Router

New returns a newly initialized Router object that implements the Router

func (*Router) DELETE

func (r *Router) DELETE(path string, handle http.HandlerFunc)

DELETE adds the route `path` that matches a DELETE http method to execute the `handle` http.HandlerFunc.

func (*Router) DELETEAndName

func (r *Router) DELETEAndName(path string, handle http.HandlerFunc, routeName string)

DELETEAndName is short for `DELETE` and Named routeName

func (*Router) GET

func (r *Router) GET(path string, handle http.HandlerFunc)

GET adds the route `path` that matches a GET http method to execute the `handle` http.HandlerFunc.

func (*Router) GETAndName

func (r *Router) GETAndName(path string, handle http.HandlerFunc, routeName string)

GETAndName is short for `GET` and Named routeName

func (*Router) Generate

func (r *Router) Generate(method string, routeName string, params map[string]string) (string, error)

Generate returns reverse routing by method, routeName and params

func (*Router) Group

func (r *Router) Group(prefix string) *Router

Group define routes groups if there is a path prefix that uses `prefix`

func (*Router) Handle

func (r *Router) Handle(method string, path string, handle http.HandlerFunc)

Handle registers a new request handler with the given path and method.

func (*Router) HandleNotFound

func (r *Router) HandleNotFound(w http.ResponseWriter, req *http.Request, middleware []MiddlewareType)

HandleNotFound registers a handler when the request route is not found

func (*Router) Match

func (r *Router) Match(requestUrl string, path string) bool

Match checks if the request matches the route pattern

func (*Router) NotFoundFunc

func (r *Router) NotFoundFunc(handler http.HandlerFunc)

NotFoundFunc registers a handler when the request route is not found

func (*Router) PATCH

func (r *Router) PATCH(path string, handle http.HandlerFunc)

PATCH adds the route `path` that matches a PATCH http method to execute the `handle` http.HandlerFunc.

func (*Router) PATCHAndName

func (r *Router) PATCHAndName(path string, handle http.HandlerFunc, routeName string)

PATCHAndName is short for `PATCH` and Named routeName

func (*Router) POST

func (r *Router) POST(path string, handle http.HandlerFunc)

POST adds the route `path` that matches a POST http method to execute the `handle` http.HandlerFunc.

func (*Router) POSTAndName

func (r *Router) POSTAndName(path string, handle http.HandlerFunc, routeName string)

POSTAndName is short for `POST` and Named routeName

func (*Router) PUT

func (r *Router) PUT(path string, handle http.HandlerFunc)

PUT adds the route `path` that matches a PUT http method to execute the `handle` http.HandlerFunc.

func (*Router) PUTAndName

func (r *Router) PUTAndName(path string, handle http.HandlerFunc, routeName string)

PUTAndName is short for `PUT` and Named routeName

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP makes the router implement the http.Handler interface.

func (*Router) Use

func (r *Router) Use(middleware ...MiddlewareType)

Use appends a middleware handler to the middleware stack.

type RouterGroup

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

func DefautlRouter

func DefautlRouter() *RouterGroup

func (*RouterGroup) Delete

func (e *RouterGroup) Delete(path string, h HandleFunc)

func (*RouterGroup) Get

func (e *RouterGroup) Get(path string, h HandleFunc)

func (*RouterGroup) NewGroupRouter

func (rg *RouterGroup) NewGroupRouter(group string) *RouterGroup

func (*RouterGroup) Patch

func (e *RouterGroup) Patch(path string, h HandleFunc)

func (*RouterGroup) Post

func (e *RouterGroup) Post(path string, h HandleFunc)

func (*RouterGroup) Put

func (e *RouterGroup) Put(path string, h HandleFunc)

func (*RouterGroup) ServeHTTP

func (e *RouterGroup) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Tree

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

Tree records node

func NewTree

func NewTree() *Tree

NewTree returns a newly initialized Tree object that implements the Tree

func (*Tree) Add

func (t *Tree) Add(pattern string, handle http.HandlerFunc, middleware ...MiddlewareType)

Add use `pattern` 、handle、middleware stack as node register to tree

func (*Tree) Find

func (t *Tree) Find(pattern string, isRegex bool) (nodes []*Node)

Find returns nodes that the request match the route pattern

Directories

Path Synopsis
Package sqlx provides general purpose extensions to database/sql.
Package sqlx provides general purpose extensions to database/sql.
reflectx
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages.
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages.

Jump to

Keyboard shortcuts

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