go-admin: github.com/GoAdminGroup/go-admin/context Index | Files

package context

import "github.com/GoAdminGroup/go-admin/context"

Index

Package Files

context.go trie.go

type App Uses

type App struct {
    Requests []Path

    Middlewares Handlers
    Prefix      string
    // contains filtered or unexported fields
}

App is the key struct of the package. App as a member of plugin entity contains the request and the corresponding handler. Prefix is the url prefix and MiddlewareList is for control flow.

func NewApp Uses

func NewApp() *App

NewApp return an empty app.

func (*App) ANY Uses

func (app *App) ANY(url string, handler ...Handler)

ANY registers a route that matches all the HTTP methods. GET, POST, PUT, HEAD, OPTIONS, DELETE.

func (*App) AppendReqAndResp Uses

func (app *App) AppendReqAndResp(url, method string, handler []Handler)

AppendReqAndResp stores the request info and handle into app. support the route parameter. The route parameter will be recognized as wildcard store into the RegUrl of Path struct. For example:

/user/:id      => /user/(.*)
/user/:id/info => /user/(.*?)/info

The RegUrl will be used to recognize the incoming path and find the handler.

func (*App) DELETE Uses

func (app *App) DELETE(url string, handler ...Handler)

DELETE is a shortcut for app.AppendReqAndResp(url, "delete", handler).

func (*App) Find Uses

func (app *App) Find(url, method string) []Handler

Find is public helper method for findPath of tree.

func (*App) GET Uses

func (app *App) GET(url string, handler ...Handler)

GET is a shortcut for app.AppendReqAndResp(url, "get", handler).

func (*App) Group Uses

func (app *App) Group(prefix string, middleware ...Handler) *RouterGroup

Group add middlewares and prefix for App.

func (*App) HEAD Uses

func (app *App) HEAD(url string, handler ...Handler)

HEAD is a shortcut for app.AppendReqAndResp(url, "head", handler).

func (*App) OPTIONS Uses

func (app *App) OPTIONS(url string, handler ...Handler)

OPTIONS is a shortcut for app.AppendReqAndResp(url, "options", handler).

func (*App) POST Uses

func (app *App) POST(url string, handler ...Handler)

POST is a shortcut for app.AppendReqAndResp(url, "post", handler).

func (*App) PUT Uses

func (app *App) PUT(url string, handler ...Handler)

PUT is a shortcut for app.AppendReqAndResp(url, "put", handler).

type Context Uses

type Context struct {
    Request   *http.Request
    Response  *http.Response
    UserValue map[string]interface{}
    // contains filtered or unexported fields
}

Context is the simplify version of web framework context. But it is important which will be used in plugins to custom the request and response. And adapter will help to transform the Context to the web framework`s context. It has three attributes. Request and response are belongs to net/http package. UserValue is the custom key-value store of context.

func NewContext Uses

func NewContext(req *http.Request) *Context

NewContext used in adapter which return a Context with request and slice of UserValue and a default Response.

func (*Context) Abort Uses

func (ctx *Context) Abort()

Abort abort the context.

func (*Context) AddHeader Uses

func (ctx *Context) AddHeader(key, value string)

AddHeader adds the key, value pair to the header.

func (*Context) Data Uses

func (ctx *Context) Data(code int, contentType string, data []byte)

Data writes some data into the body stream and updates the HTTP code.

func (*Context) FormValue Uses

func (ctx *Context) FormValue(key string) string

FormValue get the value of request form key.

func (*Context) HTML Uses

func (ctx *Context) HTML(code int, body string)

HTML output html response.

func (*Context) Headers Uses

func (ctx *Context) Headers(key string) string

Headers get the value of request headers key.

func (*Context) JSON Uses

func (ctx *Context) JSON(code int, Body map[string]interface{})

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

func (*Context) LocalIP Uses

func (ctx *Context) LocalIP() string

LocalIP return the request client ip.

func (*Context) Method Uses

func (ctx *Context) Method() string

Method return the request method.

func (*Context) Next Uses

func (ctx *Context) Next()

Next should be used only inside middleware.

func (*Context) Path Uses

func (ctx *Context) Path() string

Path return the url path.

func (*Context) PostForm Uses

func (ctx *Context) PostForm() url.Values

PostForm get the values of request form.

func (*Context) Query Uses

func (ctx *Context) Query(key string) string

Query get the query parameter of url.

func (*Context) QueryDefault Uses

func (ctx *Context) QueryDefault(key, def string) string

QueryDefault get the query parameter of url. If it is empty, return the default.

func (*Context) Redirect Uses

func (ctx *Context) Redirect(path string)

Redirect add redirect url to header.

func (*Context) SetContentType Uses

func (ctx *Context) SetContentType(contentType string)

SetContentType save the given content type header into the response header.

func (*Context) SetCookie Uses

func (ctx *Context) SetCookie(cookie *http.Cookie)

SetCookie save the given cookie obj into the response Set-Cookie header.

func (*Context) SetHandlers Uses

func (ctx *Context) SetHandlers(handlers Handlers) *Context

SetHandlers set the handlers of Context.

func (*Context) SetHeader Uses

func (ctx *Context) SetHeader(key, value string)

SetHeader set the key, value pair to the header.

func (*Context) SetStatusCode Uses

func (ctx *Context) SetStatusCode(code int)

SetStatusCode save the given status code into the response.

func (*Context) SetUserValue Uses

func (ctx *Context) SetUserValue(key string, value interface{})

SetUserValue set the value of user context.

func (*Context) User Uses

func (ctx *Context) User() interface{}

User return the current login user.

func (*Context) Write Uses

func (ctx *Context) Write(code int, Header map[string]string, Body string)

Write save the given status code, header and body string into the response.

func (*Context) WriteString Uses

func (ctx *Context) WriteString(Body string)

WriteString save the given body string into the response.

type Handler Uses

type Handler func(ctx *Context)

Handler defines the handler used by the middleware as return value.

type Handlers Uses

type Handlers []Handler

Handlers is the array of Handler

type Node Uses

type Node struct {
    Path     string
    Method   string
    Handlers []Handler
}

type Path Uses

type Path struct {
    URL    string
    Method string
}

Path is used in the matching of request and response. Url stores the raw register url. RegUrl contains the wildcard which on behalf of the route params.

type RouterGroup Uses

type RouterGroup struct {
    Middlewares Handlers
    Prefix      string
    // contains filtered or unexported fields
}

RouterGroup is a group of routes.

func (*RouterGroup) ANY Uses

func (g *RouterGroup) ANY(url string, handler ...Handler)

ANY registers a route that matches all the HTTP methods. GET, POST, PUT, HEAD, OPTIONS, DELETE.

func (*RouterGroup) AppendReqAndResp Uses

func (g *RouterGroup) AppendReqAndResp(url, method string, handler []Handler)

AppendReqAndResp stores the request info and handle into app. support the route parameter. The route parameter will be recognized as wildcard store into the RegUrl of Path struct. For example:

/user/:id      => /user/(.*)
/user/:id/info => /user/(.*?)/info

The RegUrl will be used to recognize the incoming path and find the handler.

func (*RouterGroup) DELETE Uses

func (g *RouterGroup) DELETE(url string, handler ...Handler)

DELETE is a shortcut for app.AppendReqAndResp(url, "delete", handler).

func (*RouterGroup) GET Uses

func (g *RouterGroup) GET(url string, handler ...Handler)

GET is a shortcut for app.AppendReqAndResp(url, "get", handler).

func (*RouterGroup) Group Uses

func (g *RouterGroup) Group(prefix string, middleware ...Handler) *RouterGroup

Group add middlewares and prefix for RouterGroup.

func (*RouterGroup) HEAD Uses

func (g *RouterGroup) HEAD(url string, handler ...Handler)

HEAD is a shortcut for app.AppendReqAndResp(url, "head", handler).

func (*RouterGroup) OPTIONS Uses

func (g *RouterGroup) OPTIONS(url string, handler ...Handler)

OPTIONS is a shortcut for app.AppendReqAndResp(url, "options", handler).

func (*RouterGroup) POST Uses

func (g *RouterGroup) POST(url string, handler ...Handler)

POST is a shortcut for app.AppendReqAndResp(url, "post", handler).

func (*RouterGroup) PUT Uses

func (g *RouterGroup) PUT(url string, handler ...Handler)

PUT is a shortcut for app.AppendReqAndResp(url, "put", handler).

Package context imports 9 packages (graph) and is imported by 39 packages. Updated 2020-01-23. Refresh now. Tools for package owners.