Documentation ¶
Index ¶
- type CloudFlareIPS
- type Ctx
- func (this *Ctx) APIServer() gcore.APIServer
- func (this *Ctx) App() gcore.App
- func (this *Ctx) ClientIP() (ip string)
- func (this *Ctx) Clone() gcore.Ctx
- func (this *Ctx) CloneWithHTTP(w http.ResponseWriter, r *http.Request, ps ...gcore.Params) gcore.Ctx
- func (this *Ctx) Config() gcore.Config
- func (this *Ctx) Conn() net.Conn
- func (this *Ctx) Controller() gcore.Controller
- func (this *Ctx) ControllerMethod() string
- func (this *Ctx) Cookie(name string) string
- func (this *Ctx) FormFile(name string, maxMultipartMemory int64) (*multipart.FileHeader, error)
- func (this *Ctx) FullPath() string
- func (this *Ctx) GET(key string, Default ...string) (val string)
- func (this *Ctx) GETArray(key string, Default ...string) (val []string)
- func (this *Ctx) GETData() (data map[string]string)
- func (this *Ctx) Get(key interface{}) (value interface{}, exists bool)
- func (this *Ctx) GetParam(key string) string
- func (this *Ctx) GetPost(key string, Default ...string) (val string)
- func (this *Ctx) Header(key string) string
- func (this *Ctx) Host() (host string)
- func (this *Ctx) I18n() gcore.I18n
- func (this *Ctx) IsAJAX() bool
- func (this *Ctx) IsDELETE() bool
- func (this *Ctx) IsGET() bool
- func (this *Ctx) IsHEAD() bool
- func (this *Ctx) IsOPTIONS() bool
- func (this *Ctx) IsPATCH() bool
- func (this *Ctx) IsPOST() bool
- func (this *Ctx) IsPUT() bool
- func (this *Ctx) IsTLSRequest() bool
- func (this *Ctx) IsWebsocket() bool
- func (this *Ctx) JSON(code int, data interface{}) (err error)
- func (this *Ctx) JSONP(code int, data interface{}) (err error)
- func (this *Ctx) JSONPTo(w io.Writer, code int, data interface{}) (err error)
- func (this *Ctx) JSONTo(w io.Writer, code int, data interface{}) (err error)
- func (this *Ctx) LocalAddr() string
- func (this *Ctx) Logger() gcore.Logger
- func (this *Ctx) MultipartForm(maxMultipartMemory int64) (*multipart.Form, error)
- func (this *Ctx) MustGet(key interface{}) (v interface{})
- func (this *Ctx) NewPager(perPage int, total int64) gcore.Paginator
- func (this *Ctx) POST(key string, Default ...string) (val string)
- func (this *Ctx) POSTArray(key string, Default ...string) (val []string)
- func (this *Ctx) POSTData() (data map[string]string)
- func (this *Ctx) Param() gcore.Params
- func (this *Ctx) PrettyJSON(code int, data interface{}) (err error)
- func (this *Ctx) PrettyJSONTo(w io.Writer, code int, data interface{}) (err error)
- func (this *Ctx) Redirect(url string) (val string)
- func (this *Ctx) RemoteAddr() string
- func (this *Ctx) Request() *http.Request
- func (this *Ctx) RequestBody() ([]byte, error)
- func (this *Ctx) Response() http.ResponseWriter
- func (this *Ctx) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (this *Ctx) Set(key interface{}, value interface{})
- func (this *Ctx) SetAPIServer(apiServer gcore.APIServer)
- func (this *Ctx) SetApp(app gcore.App)
- func (this *Ctx) SetConfig(config gcore.Config)
- func (this *Ctx) SetConn(conn net.Conn)
- func (this *Ctx) SetController(controller gcore.Controller)
- func (this *Ctx) SetControllerMethod(controllerMethod string)
- func (this *Ctx) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (this *Ctx) SetHeader(key, value string)
- func (this *Ctx) SetI18n(i18n gcore.I18n)
- func (this *Ctx) SetLocalAddr(localAddr string)
- func (this *Ctx) SetLogger(logger gcore.Logger)
- func (this *Ctx) SetParam(param gcore.Params)
- func (this *Ctx) SetRemoteAddr(remoteAddr string)
- func (this *Ctx) SetRequest(request *http.Request)
- func (this *Ctx) SetResponse(response http.ResponseWriter)
- func (this *Ctx) SetTemplate(template gcore.Template)
- func (this *Ctx) SetTimeUsed(t time.Duration)
- func (this *Ctx) SetWebServer(webServer gcore.HTTPServer)
- func (this *Ctx) Status(code int)
- func (this *Ctx) StatusCode() int
- func (this *Ctx) Stop(msg ...interface{})
- func (this *Ctx) StopJSON(code int, msg interface{})
- func (this *Ctx) Template() gcore.Template
- func (this *Ctx) TimeUsed() time.Duration
- func (this *Ctx) WebServer() gcore.HTTPServer
- func (this *Ctx) Write(data ...interface{}) (n int, err error)
- func (this *Ctx) WriteCount() int64
- func (this *Ctx) WriteE(data ...interface{}) (n int, err error)
- func (this *Ctx) WriteFile(filepath string)
- func (this *Ctx) WriteFileAttachment(filepath, filename string)
- func (this *Ctx) WriteFileFromFS(filepath string, fs http.FileSystem)
- func (this *Ctx) WriteHeader(statusCode int)
- func (this *Ctx) WriteTo(w io.Writer, data ...interface{}) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloudFlareIPS ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
func NewCtxFromConfig ¶
func NewCtxFromConfigFile ¶
func NewCtxWithHTTP ¶
func NewCtxWithHTTP(w http.ResponseWriter, r *http.Request) *Ctx
func (*Ctx) ClientIP ¶
ClientIP acquires the real client ip, search in X-Forwarded-For, X-Real-IP, request.RemoteAddr.
func (*Ctx) CloneWithHTTP ¶
func (*Ctx) Controller ¶
func (this *Ctx) Controller() gcore.Controller
func (*Ctx) ControllerMethod ¶
func (*Ctx) Cookie ¶
Cookie returns the named cookie provided in the request or ErrNoCookie if not found. And return the named cookie is unescaped. If multiple cookies match the given name, only one cookie will be returned.
func (*Ctx) FormFile ¶
FormFile returns the first file for the provided form key. maxMultipartMemory limits the request form parser using memory byte size.
func (*Ctx) FullPath ¶
FullPath returns a matched route full path. For not found routes returns an empty string.
router.GET("/user/:id", func(c gcore.Ctx) { c.FullPath() == "/user/:id" // true })
func (*Ctx) Get ¶
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*Ctx) GetParam ¶
GetParam returns the value of the URL param. It is a shortcut for c.Param().ByName(key)
router.GET("/user/:id", func(c *gcore.Ctx) { // a GET request to /user/john id := c.Param("id") // id == "john" })
func (*Ctx) IsTLSRequest ¶
func (*Ctx) IsWebsocket ¶
IsWebsocket returns true if the request headers indicate that a websocket handshake is being initiated by the client.
func (*Ctx) JSON ¶
JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".
func (*Ctx) JSONP ¶
JSONP serializes the given struct as JSON into the response body. It sets the Content-Type as "application/javascript".
func (*Ctx) JSONPTo ¶
JSONPTo serializes the given struct as JSON into the io.Writer body. It sets the Content-Type as "application/javascript".
func (*Ctx) JSONTo ¶
JSONTo serializes the given struct as JSON into the io.Writer. It also sets the Content-Type as "application/json".
func (*Ctx) MultipartForm ¶
MultipartForm is the parsed multipart form, including file uploads. maxMultipartMemory limits the request form parser using memory byte size.
func (*Ctx) MustGet ¶
func (this *Ctx) MustGet(key interface{}) (v interface{})
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*Ctx) POSTArray ¶
POSTArray returns a slice of strings for a given form key. The length of the slice depends on the number of params with the given key.
func (*Ctx) PrettyJSON ¶
PrettyJSON serializes the given struct as pretty JSON (indented) into the response body. It also sets the Content-Type as "application/json". WARNING: we recommend to use this only for development purposes since printing pretty JSON is more CPU and bandwidth consuming. Use Ctx.JSON() instead.
func (*Ctx) PrettyJSONTo ¶
PrettyJSONTo serializes the given struct as pretty JSON (indented) into the io.Writers. It also sets the Content-Type as "application/json". WARNING: we recommend to use this only for development purposes since printing pretty JSON is more CPU and bandwidth consuming. Use Ctx.JSON() instead.
func (*Ctx) Redirect ¶
Redirect redirects to the url, using http location header, and sets http code 302
func (*Ctx) RemoteAddr ¶
func (*Ctx) RequestBody ¶
RequestBody returns raw request body data.
func (*Ctx) Response ¶
func (this *Ctx) Response() http.ResponseWriter
func (*Ctx) SaveUploadedFile ¶
func (this *Ctx) SaveUploadedFile(file *multipart.FileHeader, dst string) error
SaveUploadedFile uploads the form file to specific dst.
func (*Ctx) Set ¶
func (this *Ctx) Set(key interface{}, value interface{})
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.Keys if it was not used previously.
func (*Ctx) SetAPIServer ¶
func (*Ctx) SetController ¶
func (this *Ctx) SetController(controller gcore.Controller)
func (*Ctx) SetControllerMethod ¶
func (*Ctx) SetCookie ¶
func (this *Ctx) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie adds a Set-Cookie header to the ResponseWriter's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
func (*Ctx) SetHeader ¶
SetHeader is a intelligent shortcut for ctx.Response().Header().Set(key, value). It writes a header in the response. If value == "", this method removes the header `ctx.Response().Header().Del(key)`
func (*Ctx) SetLocalAddr ¶
func (*Ctx) SetRemoteAddr ¶
func (*Ctx) SetRequest ¶
func (*Ctx) SetResponse ¶
func (this *Ctx) SetResponse(response http.ResponseWriter)
func (*Ctx) SetTemplate ¶
func (*Ctx) SetTimeUsed ¶
SetTimeUsed sets the method cost time, only for middleware2 and middleware3, do not call this.
func (*Ctx) SetWebServer ¶
func (this *Ctx) SetWebServer(webServer gcore.HTTPServer)
func (*Ctx) StatusCode ¶
StatusCode returns http code in response, if not set, default is 200.
func (*Ctx) Stop ¶
func (this *Ctx) Stop(msg ...interface{})
Stop will exit controller method or api handle function at once.
func (*Ctx) StopJSON ¶
StopJSON will exit controller method or api handle function at once. And writes the status code and a JSON body. It also sets the Content-Type as "application/json".
func (*Ctx) TimeUsed ¶
TimeUsed acquires the method cost time, only for middleware2 and middleware3.
func (*Ctx) WebServer ¶
func (this *Ctx) WebServer() gcore.HTTPServer
func (*Ctx) WriteCount ¶
WriteCount acquires outgoing bytes count by writer
func (*Ctx) WriteFile ¶
WriteFile writes the specified file into the body stream in an efficient way.
func (*Ctx) WriteFileAttachment ¶
WriteFileAttachment writes the specified file into the body stream in an efficient way On the client side, the file will typically be downloaded with the given filename
func (*Ctx) WriteFileFromFS ¶
func (this *Ctx) WriteFileFromFS(filepath string, fs http.FileSystem)
WriteFileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
func (*Ctx) WriteHeader ¶
WriteHeader sets http code in response