gctx

package
v0.0.0-...-3e416e1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudFlareIPS

type CloudFlareIPS struct {
	Result struct {
		Ipv4Cidrs []string `json:"ipv4_cidrs"`
		Ipv6Cidrs []string `json:"ipv6_cidrs"`
		Etag      string   `json:"etag"`
	} `json:"result"`
	Success  bool          `json:"success"`
	Errors   []interface{} `json:"errors"`
	Messages []interface{} `json:"messages"`
}

type Ctx

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

func NewCtx

func NewCtx() *Ctx

func NewCtxFromConfig

func NewCtxFromConfig(c gcore.Config) *Ctx

func NewCtxFromConfigFile

func NewCtxFromConfigFile(file string) (ctx *Ctx, err error)

func NewCtxWithHTTP

func NewCtxWithHTTP(w http.ResponseWriter, r *http.Request) *Ctx

func (*Ctx) APIServer

func (this *Ctx) APIServer() gcore.APIServer

func (*Ctx) App

func (this *Ctx) App() gcore.App

func (*Ctx) ClientIP

func (this *Ctx) ClientIP() (ip string)

ClientIP acquires the real client ip, search in X-Forwarded-For, X-Real-IP, request.RemoteAddr.

func (*Ctx) Clone

func (this *Ctx) Clone() gcore.Ctx

func (*Ctx) CloneWithHTTP

func (this *Ctx) CloneWithHTTP(w http.ResponseWriter, r *http.Request, ps ...gcore.Params) gcore.Ctx

func (*Ctx) Config

func (this *Ctx) Config() gcore.Config

func (*Ctx) Conn

func (this *Ctx) Conn() net.Conn

func (*Ctx) Controller

func (this *Ctx) Controller() gcore.Controller

func (*Ctx) ControllerMethod

func (this *Ctx) ControllerMethod() string

func (*Ctx) Cookie

func (this *Ctx) Cookie(name string) string

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

func (this *Ctx) FormFile(name string, maxMultipartMemory int64) (*multipart.FileHeader, error)

FormFile returns the first file for the provided form key. maxMultipartMemory limits the request form parser using memory byte size.

func (*Ctx) FullPath

func (this *Ctx) FullPath() string

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

func (this *Ctx) GET(key string, Default ...string) (val string)

GET gets the first value associated with the given key in url query.

func (*Ctx) GETArray

func (this *Ctx) GETArray(key string, Default ...string) (val []string)

GETArray returns a slice of strings for a given query key.

func (*Ctx) GETData

func (this *Ctx) GETData() (data map[string]string)

GETData gets full k,v query data from request url.

func (*Ctx) Get

func (this *Ctx) Get(key interface{}) (value interface{}, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)

func (*Ctx) GetParam

func (this *Ctx) GetParam(key string) string

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) GetPost

func (this *Ctx) GetPost(key string, Default ...string) (val string)

GetPost gets the first value associated with the given key in GET or POST.

func (*Ctx) Header

func (this *Ctx) Header(key string) string

Header returns value from request headers.

func (*Ctx) Host

func (this *Ctx) Host() (host string)

Host returns the HOST in requested HTTP HEADER.

func (*Ctx) I18n

func (this *Ctx) I18n() gcore.I18n

func (*Ctx) IsAJAX

func (this *Ctx) IsAJAX() bool

IsAJAX returns true if the request is jquery AJAX request.

func (*Ctx) IsDELETE

func (this *Ctx) IsDELETE() bool

IsDELETE returns true if the request is DELETE request.

func (*Ctx) IsGET

func (this *Ctx) IsGET() bool

IsGET returns true if the request is GET request.

func (*Ctx) IsHEAD

func (this *Ctx) IsHEAD() bool

IsHEAD returns true if the request is HEAD request.

func (*Ctx) IsOPTIONS

func (this *Ctx) IsOPTIONS() bool

IsOPTIONS returns true if the request is OPTIONS request.

func (*Ctx) IsPATCH

func (this *Ctx) IsPATCH() bool

IsPATCH returns true if the request is PATCH request.

func (*Ctx) IsPOST

func (this *Ctx) IsPOST() bool

IsPOST returns true if the request is POST request.

func (*Ctx) IsPUT

func (this *Ctx) IsPUT() bool

IsPUT returns true if the request is PUT request.

func (*Ctx) IsTLSRequest

func (this *Ctx) IsTLSRequest() bool

func (*Ctx) IsWebsocket

func (this *Ctx) IsWebsocket() bool

IsWebsocket returns true if the request headers indicate that a websocket handshake is being initiated by the client.

func (*Ctx) JSON

func (this *Ctx) JSON(code int, data interface{}) (err error)

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

func (*Ctx) JSONP

func (this *Ctx) JSONP(code int, data interface{}) (err error)

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

func (*Ctx) JSONPTo

func (this *Ctx) JSONPTo(w io.Writer, code int, data interface{}) (err error)

JSONPTo serializes the given struct as JSON into the io.Writer body. It sets the Content-Type as "application/javascript".

func (*Ctx) JSONTo

func (this *Ctx) JSONTo(w io.Writer, code int, data interface{}) (err error)

JSONTo serializes the given struct as JSON into the io.Writer. It also sets the Content-Type as "application/json".

func (*Ctx) LocalAddr

func (this *Ctx) LocalAddr() string

func (*Ctx) Logger

func (this *Ctx) Logger() gcore.Logger

func (*Ctx) MultipartForm

func (this *Ctx) MultipartForm(maxMultipartMemory int64) (*multipart.Form, error)

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) NewPager

func (this *Ctx) NewPager(perPage int, total int64) gcore.Paginator

NewPager create a new paginator used for template

func (*Ctx) POST

func (this *Ctx) POST(key string, Default ...string) (val string)

POST gets the first value associated with the given key in post body.

func (*Ctx) POSTArray

func (this *Ctx) POSTArray(key string, Default ...string) (val []string)

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) POSTData

func (this *Ctx) POSTData() (data map[string]string)

POSTData gets full k,v query data from request FORM.

func (*Ctx) Param

func (this *Ctx) Param() gcore.Params

func (*Ctx) PrettyJSON

func (this *Ctx) PrettyJSON(code int, data interface{}) (err error)

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

func (this *Ctx) PrettyJSONTo(w io.Writer, code int, data interface{}) (err error)

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

func (this *Ctx) Redirect(url string) (val string)

Redirect redirects to the url, using http location header, and sets http code 302

func (*Ctx) RemoteAddr

func (this *Ctx) RemoteAddr() string

func (*Ctx) Request

func (this *Ctx) Request() *http.Request

func (*Ctx) RequestBody

func (this *Ctx) RequestBody() ([]byte, error)

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 (this *Ctx) SetAPIServer(apiServer gcore.APIServer)

func (*Ctx) SetApp

func (this *Ctx) SetApp(app gcore.App)

func (*Ctx) SetConfig

func (this *Ctx) SetConfig(config gcore.Config)

func (*Ctx) SetConn

func (this *Ctx) SetConn(conn net.Conn)

func (*Ctx) SetController

func (this *Ctx) SetController(controller gcore.Controller)

func (*Ctx) SetControllerMethod

func (this *Ctx) SetControllerMethod(controllerMethod string)

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

func (this *Ctx) SetHeader(key, value string)

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) SetI18n

func (this *Ctx) SetI18n(i18n gcore.I18n)

func (*Ctx) SetLocalAddr

func (this *Ctx) SetLocalAddr(localAddr string)

func (*Ctx) SetLogger

func (this *Ctx) SetLogger(logger gcore.Logger)

func (*Ctx) SetParam

func (this *Ctx) SetParam(param gcore.Params)

func (*Ctx) SetRemoteAddr

func (this *Ctx) SetRemoteAddr(remoteAddr string)

func (*Ctx) SetRequest

func (this *Ctx) SetRequest(request *http.Request)

func (*Ctx) SetResponse

func (this *Ctx) SetResponse(response http.ResponseWriter)

func (*Ctx) SetTemplate

func (this *Ctx) SetTemplate(template gcore.Template)

func (*Ctx) SetTimeUsed

func (this *Ctx) SetTimeUsed(t time.Duration)

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) Status

func (this *Ctx) Status(code int)

Status sets the HTTP response code.

func (*Ctx) StatusCode

func (this *Ctx) StatusCode() int

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

func (this *Ctx) StopJSON(code int, msg interface{})

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) Template

func (this *Ctx) Template() gcore.Template

func (*Ctx) TimeUsed

func (this *Ctx) TimeUsed() time.Duration

TimeUsed acquires the method cost time, only for middleware2 and middleware3.

func (*Ctx) WebServer

func (this *Ctx) WebServer() gcore.HTTPServer

func (*Ctx) Write

func (this *Ctx) Write(data ...interface{}) (n int, err error)

Write output data to response

func (*Ctx) WriteCount

func (this *Ctx) WriteCount() int64

WriteCount acquires outgoing bytes count by writer

func (*Ctx) WriteE

func (this *Ctx) WriteE(data ...interface{}) (n int, err error)

WriteE outputs data to response and sets http status code 500

func (*Ctx) WriteFile

func (this *Ctx) WriteFile(filepath string)

WriteFile writes the specified file into the body stream in an efficient way.

func (*Ctx) WriteFileAttachment

func (this *Ctx) WriteFileAttachment(filepath, filename string)

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

func (this *Ctx) WriteHeader(statusCode int)

WriteHeader sets http code in response

func (*Ctx) WriteTo

func (this *Ctx) WriteTo(w io.Writer, data ...interface{}) (n int, err error)

WriteTo output data to io.writer

Jump to

Keyboard shortcuts

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