{"modulePath":"github.com/cppfuns/go-admin","version":"v0.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package context\n\n## Functions\n\n```go\nfunc Tree() *node\n```\n\n## Types\n\n```go\ntype App struct {\n\tRequests []Path\n\n\tMiddlewareList []Middleware\n\tPrefix         string\n\t// contains filtered or unexported fields\n}\n```\nApp 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.\n\n```go\nfunc NewApp() *App\n```\nNewApp return an empty app.\n\n```go\nfunc (app *App) ANY(url string, handler Handler)\n```\nAny registers a route that matches all the HTTP methods. GET, POST, PUT, HEAD, OPTIONS, DELETE.\n\n```go\nfunc (app *App) AppendReqAndResp(url, method string, handler Handler)\n```\nAppendReqAndResp 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:\n\n\t/user/:id      =\u003e /user/(.*)\n\t/user/:id/info =\u003e /user/(.*?)/info\n\nThe RegUrl will be used to recognize the incoming path and find the handler.\n\n```go\nfunc (app *App) DELETE(url string, handler Handler)\n```\nDELETE is a shortcut for app.AppendReqAndResp(url, \"delete\", handler).\n\n```go\nfunc (app *App) Find(url, method string) Handler\n```\nFind is public helper method for findPath of tree.\n\n```go\nfunc (app *App) GET(url string, handler Handler)\n```\nGET is a shortcut for app.AppendReqAndResp(url, \"get\", handler).\n\n```go\nfunc (app *App) Group(prefix string, middleware ...Middleware)\n```\nGroup add middlewares and prefix for App.\n\n```go\nfunc (app *App) HEAD(url string, handler Handler)\n```\nHEAD is a shortcut for app.AppendReqAndResp(url, \"head\", handler).\n\n```go\nfunc (app *App) OPTIONS(url string, handler Handler)\n```\nOPTIONS is a shortcut for app.AppendReqAndResp(url, \"options\", handler).\n\n```go\nfunc (app *App) POST(url string, handler Handler)\n```\nPOST is a shortcut for app.AppendReqAndResp(url, \"post\", handler).\n\n```go\nfunc (app *App) PUT(url string, handler Handler)\n```\nPUT is a shortcut for app.AppendReqAndResp(url, \"put\", handler).\n\n```go\ntype Context struct {\n\tRequest   *http.Request\n\tResponse  *http.Response\n\tUserValue map[string]interface{}\n}\n```\nContext 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.\n\n```go\nfunc NewContext(req *http.Request) *Context\n```\nNewContext used in adapter which return a Context with request and slice of UserValue and a default Response.\n\n```go\nfunc (ctx *Context) Json(code int, Body map[string]interface{})\n```\nJson serializes the given struct as JSON into the response body. It also sets the Content-Type as \"application/json\".\n\n```go\nfunc (ctx *Context) LocalIP() string\n```\nLocalIP return the request client ip.\n\n```go\nfunc (ctx *Context) Method() string\n```\nMethod return the request method.\n\n```go\nfunc (ctx *Context) Path() string\n```\nPath return the url path.\n\n```go\nfunc (ctx *Context) SetContentType(contentType string)\n```\nSetStatusCode save the given content type header into the response header.\n\n```go\nfunc (ctx *Context) SetCookie(cookie *http.Cookie)\n```\nSetCookie save the given cookie obj into the response Set-Cookie header.\n\n```go\nfunc (ctx *Context) SetStatusCode(code int)\n```\nSetStatusCode save the given status code into the response.\n\n```go\nfunc (ctx *Context) SetUserValue(key string, value interface{})\n```\nSetUserValue set the value of user context.\n\n```go\nfunc (ctx *Context) Write(code int, Header map[string]string, Body string)\n```\nWrite save the given status code, header and body string into the response.\n\n```go\nfunc (ctx *Context) WriteString(Body string)\n```\nWrite save the given body string into the response.\n\n```go\ntype Handler func(ctx *Context)\n```\n\n```go\ntype Middleware func(handler Handler) Handler\n```\n\n```go\ntype Path struct {\n\tURL    string\n\tMethod string\n}\n```\nPath 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.\n\n","path":"github.com/cppfuns/go-admin/context","name":"context","synopsis":"","isRedistributable":true}
