Documentation ¶
Index ¶
- Constants
- func StringToBytes(s string) []byte
- func SubStringLast(str string, substr string) string
- type Context
- func (c *Context) DefaultQuery(key, defaultValue string) string
- func (c *Context) File(fileName string)
- func (c *Context) FileAttachment(filepath, filename string)
- func (c *Context) FileFromFS(filepath string, fs http.FileSystem)
- func (c *Context) GetAllQuery(key string) ([]string, bool)
- func (c *Context) GetQuery(key string) string
- func (c *Context) GetQueryMap(key string) (map[string]string, bool)
- func (c *Context) HTML(status int, html string) error
- func (c *Context) HTMLTemplate(name string, data any, filename ...string) error
- func (c *Context) HTMLTemplateGlob(name string, data any, pattern string) error
- func (c *Context) JSON(status int, data any) error
- func (c *Context) QueryArray(key string) (values []string)
- func (c *Context) QueryMap(key string) (dicts map[string]string)
- func (c *Context) Redirect(status int, url string) error
- func (c *Context) Render(statusCode int, r render.Render) error
- func (c *Context) String(status int, format string, values ...any) error
- func (c *Context) Template(name string, data any) error
- func (c *Context) XML(status int, data any) error
- type Engine
- type HandleFunc
- type MiddlewareFunc
Constants ¶
const ANY = "ANY"
ANY is the other name of "ANY" means url use ANY method
Variables ¶
This section is empty.
Functions ¶
func StringToBytes ¶
StringToBytes use unsafe pointer it will not copy the memory
func SubStringLast ¶
Types ¶
type Context ¶
type Context struct { W http.ResponseWriter // response R *http.Request // request // contains filtered or unexported fields }
Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example
func (*Context) DefaultQuery ¶
DefaultQuery if you have not set the key return the default value
func (*Context) FileAttachment ¶
FileAttachment 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 (*Context) FileFromFS ¶
func (c *Context) FileFromFS(filepath string, fs http.FileSystem)
FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
func (*Context) GetAllQuery ¶
GetAllQuery if you want to all the url query param by using key like ?id=1&id=2 return [1, 2]
func (*Context) GetQueryMap ¶
GetQueryMap get the mapping
func (*Context) HTML ¶
HTML Render the HTML files to request it return pure HTML files, don't need any data
func (*Context) HTMLTemplate ¶
HTMLTemplate is the function to render the HTML Template return HTML template files with data
func (*Context) HTMLTemplateGlob ¶
HTMLTemplate is the function to render the HTML Template you set
func (*Context) JSON ¶
JSON serializes the given struct as JSON into the response body. It also sets the Content-Type as "application/json".
func (*Context) QueryArray ¶
QueryArray return query param without check
type Engine ¶
type Engine struct { HTMLRender render.HTMLRender // contains filtered or unexported fields }
Engine is the framework's instance, it contains the muxer, middleware and configuration settings. Create an instance of Engine, by using New() or Default().
func New ¶
func New() *Engine
New returns a new blank Engine instance without any middleware attached.
func (Engine) Group ¶
func (r Engine) Group(name string) *routerGroup
Group grouping the routes initialize the routerGroups by using the Group function take the routerGroup to manipulate the url
func (*Engine) LoadHTMLTemplate ¶
func (*Engine) Run ¶
func (e *Engine) Run()
Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.
func (*Engine) ServeHTTP ¶
func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)
implement the interface method ServeHTTP
func (*Engine) SetFuncMap ¶
SetFuncMap SetHTMLTemplate LoadHTMLTemplate These three function is to render the html template files in memory
func (*Engine) SetHTMLTemplate ¶
type HandleFunc ¶
type HandleFunc func(ctx *Context)
HandleFunc defines the handler used by vex middleware as return value. Context is the wrap of (w *http.ResponseWriter, r http.Request)
type MiddlewareFunc ¶
type MiddlewareFunc func(handleFunc HandleFunc) HandleFunc
MiddlewareFunc is code before or after HandleFunc input the handleFunc before process then return the handle Func which after process