Documentation ¶
Overview ¶
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2021 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2021 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2022 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Copyright 2020 GoFast Author(http://chende.ren). All rights reserved. Use of this source code is governed by a MIT license
Index ¶
- Constants
- func Dir(root string, listDirectory bool) http.FileSystem
- func GFPanic(val any)
- func GFPanicErr(err error)
- func GFPanicIf(yes bool, val any)
- type AppHandler
- type Context
- func (c *Context) AbortDirect(resStatus int, stream any)
- func (c *Context) AbortFai(code int, msg string)
- func (c *Context) AbortRedirect(resStatus int, redirectUrl string)
- func (c *Context) AddMsgBasket(msg string)
- func (c *Context) Bind(dst any) error
- func (c *Context) BuildPms() error
- func (c *Context) ClientIP() string
- func (c *Context) ContentType() string
- func (c *Context) Fai(code int32, msg string, data any)
- func (c *Context) FaiCode(code int32)
- func (c *Context) FaiData(data any)
- func (c *Context) FaiErr(err error)
- func (c *Context) FaiMsg(msg string)
- func (c *Context) FaiPanicIf(yes bool, val any)
- func (c *Context) FaiRet(ret *Ret)
- func (c *Context) File(filepath string)
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FullPath() string
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) GetBool(key string) (bool, error)
- func (c *Context) GetBoolDef(key string, def bool) bool
- func (c *Context) GetBoolMust(key string) bool
- func (c *Context) GetDuration(key string) (time.Duration, error)
- func (c *Context) GetDurationDef(key string, def time.Duration) time.Duration
- func (c *Context) GetDurationMust(key string) time.Duration
- func (c *Context) GetFloat32(key string) (float32, error)
- func (c *Context) GetFloat32Def(key string, def float32) float32
- func (c *Context) GetFloat32Must(key string) float32
- func (c *Context) GetFloat64(key string) (float64, error)
- func (c *Context) GetFloat64Def(key string, def float64) float64
- func (c *Context) GetFloat64Must(key string) float64
- func (c *Context) GetHeader(key string) string
- func (c *Context) GetInt(key string) (int, error)
- func (c *Context) GetInt16(key string) (int16, error)
- func (c *Context) GetInt16Def(key string, def int16) int16
- func (c *Context) GetInt16Must(key string) int16
- func (c *Context) GetInt32(key string) (int32, error)
- func (c *Context) GetInt32Def(key string, def int32) int32
- func (c *Context) GetInt32Must(key string) int32
- func (c *Context) GetInt64(key string) (int64, error)
- func (c *Context) GetInt64Def(key string, def int64) int64
- func (c *Context) GetInt64Must(key string) int64
- func (c *Context) GetInt8(key string) (int8, error)
- func (c *Context) GetInt8Def(key string, def int8) int8
- func (c *Context) GetInt8Must(key string) int8
- func (c *Context) GetIntDef(key string, def int) int
- func (c *Context) GetIntMust(key string) int
- func (c *Context) GetMust(key string) any
- func (c *Context) GetString(key string) (string, error)
- func (c *Context) GetStringDef(key string, def string) string
- func (c *Context) GetStringMust(key string) string
- func (c *Context) GetTime(key string) (*time.Time, error)
- func (c *Context) GetTimeDef(key string, def *time.Time) *time.Time
- func (c *Context) GetTimeMust(key string) *time.Time
- func (c *Context) GetUint(key string) (uint, error)
- func (c *Context) GetUint16(key string) (uint16, error)
- func (c *Context) GetUint16Def(key string, def uint16) uint16
- func (c *Context) GetUint16Must(key string) uint16
- func (c *Context) GetUint32(key string) (uint32, error)
- func (c *Context) GetUint32Def(key string, def uint32) uint32
- func (c *Context) GetUint32Must(key string) uint32
- func (c *Context) GetUint64(key string) (uint64, error)
- func (c *Context) GetUint64Def(key string, def uint64) uint64
- func (c *Context) GetUint64Must(key string) uint64
- func (c *Context) GetUint8(key string) (uint8, error)
- func (c *Context) GetUint8Def(key string, def uint8) uint8
- func (c *Context) GetUint8Must(key string) uint8
- func (c *Context) GetUintDef(key string, def uint) uint
- func (c *Context) GetUintMust(key string) uint
- func (c *Context) IsWebsocket() bool
- func (c *Context) Json(resStatus int, obj any)
- func (c *Context) MsgBaskets() tools.Baskets
- func (c *Context) MultipartForm() (*multipart.Form, error)
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) ParseForm()
- func (c *Context) ParseQuery()
- func (c *Context) PostForm(key string) string
- func (c *Context) PostForm2(key string) (string, bool)
- func (c *Context) PostFormArray(key string) []string
- func (c *Context) PostFormArray2(key string) ([]string, bool)
- func (c *Context) PostFormDef(key, defaultValue string) string
- func (c *Context) PostFormMap(key string) map[string]string
- func (c *Context) PostFormMap2(key string) (map[string]string, bool)
- func (c *Context) Query(key string) string
- func (c *Context) Query2(key string) (string, bool)
- func (c *Context) QueryArray(key string) []string
- func (c *Context) QueryArray2(key string) ([]string, bool)
- func (c *Context) QueryDef(key, defaultValue string) string
- func (c *Context) QueryMap(key string) map[string]string
- func (c *Context) QueryMap2(key string) (map[string]string, bool)
- func (c *Context) Render(resStatus int, r render.Render)
- func (c *Context) RenderTimeout(resStatus int, hint any) bool
- func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetRouteTo404()
- func (c *Context) SetRouteTo405()
- func (c *Context) SetRouteToAny()
- func (c *Context) String(resStatus int, format string, values ...any)
- func (c *Context) Suc(code int32, msg string, data any)
- func (c *Context) SucCode(code int32)
- func (c *Context) SucData(data any)
- func (c *Context) SucMsg(msg string)
- func (c *Context) SucRet(ret *Ret)
- type CtxHandler
- type GfConfig
- type GoFast
- func (gft *GoFast) BuildRoutes()
- func (gft *GoFast) FullPath(idx uint16) string
- func (gft *GoFast) GracefulShutdown()
- func (gft *GoFast) IsDebugging() bool
- func (gft *GoFast) Listen(addr ...string) (err error)
- func (gft *GoFast) On(eType string, handles ...AppHandler)
- func (gft *GoFast) OnAfterBuildRoutes(hds ...AppHandler)
- func (gft *GoFast) OnBeforeBuildRoutes(hds ...AppHandler)
- func (gft *GoFast) OnClose(hds ...AppHandler)
- func (gft *GoFast) OnReady(hds ...AppHandler)
- func (gft *GoFast) ProjectName() (name string)
- func (gft *GoFast) Reg404(hds ...CtxHandler)
- func (gft *GoFast) Reg405(hds ...CtxHandler)
- func (gft *GoFast) RoutePaths() []string
- func (gft *GoFast) RoutePathsWithMethod() []string
- func (gft *GoFast) RoutesLen() uint16
- func (gft *GoFast) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (gft *GoFast) SetMode(mode string)
- func (gft *GoFast) SpecialAfter(hds ...CtxHandler)
- func (gft *GoFast) SpecialBefore(hds ...CtxHandler)
- func (gft *GoFast) SpecialRoutePaths() []string
- func (gft *GoFast) SpecialRoutesLen() uint16
- func (gft *GoFast) UseGlobal(inject injectFunc) *GoFast
- func (gft *GoFast) UseHttpHandler(hds HttpHandler) *GoFast
- type HomeRouter
- type HttpHandler
- type ResData
- type ResponseWrap
- func (w *ResponseWrap) DataSize() int
- func (w *ResponseWrap) Flush() bool
- func (w *ResponseWrap) HeaderValues() http.Header
- func (w *ResponseWrap) Reset(res http.ResponseWriter)
- func (w *ResponseWrap) Send() (n int, err error)
- func (w *ResponseWrap) SendHijack(resStatus int, data []byte) (n int)
- func (w *ResponseWrap) SendHijackRedirect(req *http.Request, resStatus int, redirectUrl string)
- func (w *ResponseWrap) Status() int
- func (w *ResponseWrap) Write(data []byte) (n int, err error)
- func (w *ResponseWrap) WriteHeader(newStatus int)
- func (w *ResponseWrap) WriteString(s string) (n int, err error)
- func (w *ResponseWrap) WrittenData() []byte
- type Ret
- type RouteAttrs
- type RouteGroup
- func (gp *RouteGroup) A(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) After(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) AfterMatch(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) AfterSend(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) All(relPath string, hds ...CtxHandler)
- func (gp *RouteGroup) B(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) Before(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) BeforeSend(hds ...CtxHandler) *RouteGroup
- func (gp *RouteGroup) Delete(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Get(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) GetPost(relPath string, hds ...CtxHandler) (get, post *RouteItem)
- func (gp *RouteGroup) Group(relPath string) *RouteGroup
- func (gp *RouteGroup) Handle(httpMethod, relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Head(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Options(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Patch(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Post(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Prefix() string
- func (gp *RouteGroup) Put(relPath string, hds ...CtxHandler) *RouteItem
- func (gp *RouteGroup) Static(relPath, root string) *RouteGroup
- func (gp *RouteGroup) StaticFS(relPath string, fs http.FileSystem) *RouteGroup
- func (gp *RouteGroup) StaticFile(relPath, filepath string) *RouteGroup
- type RouteItem
- func (ri *RouteItem) A(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) After(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) AfterMatch(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) AfterSend(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) Attrs(ra RouteAttrs) *RouteItem
- func (ri *RouteItem) B(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) Before(hds ...CtxHandler) *RouteItem
- func (ri *RouteItem) BeforeSend(hds ...CtxHandler) *RouteItem
- type SessionKeeper
- type UrlParam
Constants ¶
const ( BasketTypeAny tools.BasketType = 0 BasketTypePrivate tools.BasketType = 1 << 0 BasketTypePublic tools.BasketType = 1 << 1 BasketTypeMsg tools.BasketType = 1 << 2 )
const ( DebugMode = "debug" DevMode = "dev" TestMode = "test" ProductMode = "product" )
const ( EBeforeBuildRoutes = "onBeforeBuildRoutes" // 开始重构路由树前 EAfterBuildRoutes = "onAfterBuildRoutes" // 重构路由树后 EReady = "onReady" // server 接收正式请求之前调用 EClose = "onClose" // server 关闭退出之前调用 )
const ( EAfterMatch = "onAfterMatch" // 初步匹配路由之后,调用这个做更进一步的自定义Check检查 EBefore = "onBefore" EAfter = "onAfter" EBeforeSend = "onBeforeSend" EAfterSend = "onAfterSend" )
Note:该设计给将来预留了足够的扩展空间 请求生命周期,设计了不同点的事件类型,这样可以自由 加入 hook
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
func Dir(root string, listDirectory bool) http.FileSystem
Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
func GFPanicErr ¶
func GFPanicErr(err error)
Types ¶
type AppHandler ¶
type AppHandler func(gft *GoFast)
type Context ¶
type Context struct { EnterTime time.Duration // 请求起始时间 ResWrap *ResponseWrap ReqRaw *http.Request // request Sess SessionKeeper // Session数据,数据存储部分可以自定义 UrlParams *routeParams // : 或 * 对应的参数 Pms cst.KV // 所有Request参数的map(queryCache + formCache)一般用于构造model对象 Baskets tools.Baskets // []*Basket,可以携带扩展的自定义数据 RouteIdx uint16 // route的唯一标识ID,方便区分不同的route // contains filtered or unexported fields }
Context is the most important part of GoFast. 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) AbortDirect ¶
强行终止处理,立即返回指定结果,不执行Render
func (*Context) AbortFai ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Abort系列函数都将终止当前 handlers 的执行 立即返回错误,跳过后面的执行链
func (*Context) AbortRedirect ¶
func (*Context) AddMsgBasket ¶
添加一项携带消息体的Basket,日志系统会打印出这些信息
func (*Context) BuildPms ¶
##这个方法很重要## 框架每次都将请求所携带的相关数据解析之后加入统一的变量c.Pms中,这样对开发人员来说只需要关注c.Pms中有无自己想要的数据, 至于数据是通过什么形式提交上来的并不那么重要。 最常见的就是GET请求URL上的参数,POST请求中req.Body携带的信息
func (*Context) ClientIP ¶
ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy. Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
func (*Context) ContentType ¶
ContentType returns the Content-Type header of the request.
func (*Context) FormFile ¶
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the first file for the provided form key.
func (*Context) GetBoolMust ¶
func (*Context) GetDurationDef ¶
func (*Context) GetFloat32Must ¶
func (*Context) GetFloat64 ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*Context) GetFloat64Must ¶
func (*Context) GetInt16Must ¶
func (*Context) GetInt32Must ¶
func (*Context) GetInt64 ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*Context) GetInt64Must ¶
func (*Context) GetInt8Must ¶
func (*Context) GetIntMust ¶
func (*Context) GetString ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*Context) GetStringMust ¶
func (*Context) GetUint16Must ¶
func (*Context) GetUint32Must ¶
func (*Context) GetUint64Must ¶
func (*Context) GetUint8Must ¶
func (*Context) GetUintMust ¶
func (*Context) IsWebsocket ¶
IsWebsocket returns true if the request headers indicate that a websocket handshake is being initiated by the client.
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) MultipartForm ¶
MultipartForm is the parsed multipart form, including file uploads.
func (*Context) Param ¶
UrlParam returns the value of the URL param. It is a shortcut for c.UrlParams.ByName(key)
router.GET("/user/:id", func(c *gin.Context) { // a GET request to /user/john id := c.UrlParam("id") // id == "john" })
func (*Context) ParseForm ¶
func (c *Context) ParseForm()
B. ++++++++++++++++++++++++++++ 解析所有 Post 数据到 PostForm对象中,同时将 PostForm 和 QueryForm 中的数据合并到 Form 中。
func (*Context) ParseQuery ¶
func (c *Context) ParseQuery()
A. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 解析 Url 中的参数
func (*Context) PostForm ¶
POST Content-type: application/x-www-form-urlencoded:默认的编码方式。但是在用文本的传输和MP3等大型文件的时候,使用这种编码就显得效率低下。 multipart/form-data:指定传输数据为二进制类型,比如图片、mp3、文件。(注意:这个时候有 boundary=--xxxx 参数) text/plain:纯文体的传输。空格转换为 “+” 加号,但不对特殊字符编码。 PostForm returns the specified key from a POST urlencoded form or multipart form when it exists, otherwise it returns an empty string `("")`.
func (*Context) PostForm2 ¶
GetPostForm is like PostForm(key). It returns the specified key from a POST urlencoded form or multipart form when it exists `(value, true)` (even when the value is an empty string), otherwise it returns ("", false). For example, during a PATCH request to update the user's email:
email=mail@example.com --> ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com" email= --> ("", true) := GetPostForm("email") // set email to "" --> ("", false) := GetPostForm("email") // do nothing with email
func (*Context) PostFormArray ¶
PostFormArray 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 (*Context) PostFormArray2 ¶
GetPostFormArray returns a slice of strings for a given form key, plus a boolean value whether at least one value exists for the given key.
func (*Context) PostFormDef ¶
DefaultPostForm returns the specified key from a POST urlencoded form or multipart form when it exists, otherwise it returns the specified defaultValue string. See: PostForm() and GetPostForm() for further information.
func (*Context) PostFormMap ¶
PostFormMap returns a map for a given form key.
func (*Context) PostFormMap2 ¶
GetPostFormMap returns a map for a given form key, plus a boolean value whether at least one value exists for the given key.
func (*Context) Query ¶
Query returns the keyed url query value if it exists, otherwise it returns an empty string `("")`. It is shortcut for `c.ReqRaw.URL.Query().Get(key)`
GET /path?id=1234&name=Manu&value= c.Query("id") == "1234" c.Query("name") == "Manu" c.Query("value") == "" c.Query("wtf") == ""
func (*Context) Query2 ¶
GetQuery is like Query(), it returns the keyed url query value if it exists `(value, true)` (even when the value is an empty string), otherwise it returns `("", false)`. It is shortcut for `c.ReqRaw.URL.Query().Get(key)`
GET /?name=Manu&lastname= ("Manu", true) == c.GetQuery("name") ("", false) == c.GetQuery("id") ("", true) == c.GetQuery("lastname")
func (*Context) QueryArray ¶
QueryArray returns a slice of strings for a given query key. The length of the slice depends on the number of params with the given key.
func (*Context) QueryArray2 ¶
GetQueryArray returns a slice of strings for a given query key, plus a boolean value whether at least one value exists for the given key.
func (*Context) QueryDef ¶
DefaultQuery returns the keyed url query value if it exists, otherwise it returns the specified defaultValue string. See: Query() and GetQuery() for further information.
GET /?name=Manu&lastname= c.DefaultQuery("name", "unknown") == "Manu" c.DefaultQuery("id", "none") == "none" c.DefaultQuery("lastname", "none") == ""
func (*Context) QueryMap2 ¶
GetQueryMap returns a map for a given query key, plus a boolean value whether at least one value exists for the given key.
func (*Context) Render ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Render writes the response headers and calls render.Render to render data. 返回数据的接口 可以自定义扩展自己需要的Render
func (*Context) RenderTimeout ¶
这个是为超时返回准备的特殊方法,一般不要使用
func (*Context) SaveUploadedFile ¶
func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error
SaveUploadedFile uploads the form file to specific dst.
func (*Context) SetRouteTo404 ¶
func (c *Context) SetRouteTo404()
func (*Context) SetRouteTo405 ¶
func (c *Context) SetRouteTo405()
func (*Context) SetRouteToAny ¶
func (c *Context) SetRouteToAny()
type CtxHandler ¶
type CtxHandler func(ctx *Context)
type GfConfig ¶
type GfConfig struct { AppName string `v:"required"` ListenAddr string `v:"def=0.0.0.0:8099,route=ipv4:port"` // 监听ip:port RunMode string `v:"def=product,enum=debug|test|product"` // 当前模式[debug|test|product] BeforeShutdownMS int64 `v:"def=1000"` // 退出server之前等待的毫秒,等待清理释放资源 LogConfig logx.LogConfig WebConfig cst.WebConfig SdxConfig cst.SdxConfig // sdx middleware configs // contains filtered or unexported fields }
GoFast WEB框架的配置参数
type GoFast ¶
type GoFast struct { *GfConfig // 引用配置 // 第二级 handlers (根路由组相关属性) *HomeRouter // 根路由组(Root Group) // contains filtered or unexported fields }
GoFast is the framework's instance. Create an instance of GoFast, by using CreateServer().
func CreateServer ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 第一步:初始化一个 WebServer , 配置各种参数
func (*GoFast) BuildRoutes ¶
func (gft *GoFast) BuildRoutes()
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NOTE:重构路由树。(重要!重要!重要!必须调用这个方法初始化路由树和中间件) 在不执行真正Listen的场景中,调用此函数能初始化服务器(必须要调用此函数来构造路由)
func (*GoFast) FullPath ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 获取相应路由节点完整URL
func (*GoFast) Listen ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 第二步:启动端口监听 说明:第一步和第二步之间,需要做所有的工作,主要就是初始化参数,设置所有的路由和处理函数
func (*GoFast) On ¶
func (gft *GoFast) On(eType string, handles ...AppHandler)
func (*GoFast) OnAfterBuildRoutes ¶
func (gft *GoFast) OnAfterBuildRoutes(hds ...AppHandler)
func (*GoFast) OnBeforeBuildRoutes ¶
func (gft *GoFast) OnBeforeBuildRoutes(hds ...AppHandler)
func (*GoFast) OnClose ¶
func (gft *GoFast) OnClose(hds ...AppHandler)
func (*GoFast) OnReady ¶
func (gft *GoFast) OnReady(hds ...AppHandler)
func (*GoFast) ProjectName ¶
func (*GoFast) Reg404 ¶
func (gft *GoFast) Reg404(hds ...CtxHandler)
每次设置都会替换掉以前设置好的方法 NoRoute adds handlers for NoRoute. It return a 404 code by default.
func (*GoFast) Reg405 ¶
func (gft *GoFast) Reg405(hds ...CtxHandler)
每次设置都会替换掉以前设置好的方法 NoMethod sets the handlers called when...
func (*GoFast) RoutePaths ¶
func (*GoFast) RoutePathsWithMethod ¶
func (*GoFast) ServeHTTP ¶
func (gft *GoFast) ServeHTTP(w http.ResponseWriter, r *http.Request)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ http服务器,所有请求的入口,底层是用 goroutine 发起的一个协程任务 也就是说主线程,获取到任何请求事件(数据)之后,通过goroutine调用这个接口方法来并行处理 这里的代码就是在一个协程中运行的 Note: 1. 这是请求进来之后的第一级上下文,为了节省内存空间,第一级的拦截器通过之后,会进入第二级更丰富的Context上下文(占用内存更多)
func (*GoFast) SpecialAfter ¶
func (gft *GoFast) SpecialAfter(hds ...CtxHandler)
func (*GoFast) SpecialBefore ¶
func (gft *GoFast) SpecialBefore(hds ...CtxHandler)
SpecialRouteGroup
func (*GoFast) SpecialRoutePaths ¶
func (*GoFast) SpecialRoutesLen ¶
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ special
func (*GoFast) UseHttpHandler ¶
func (gft *GoFast) UseHttpHandler(hds HttpHandler) *GoFast
添加单个全局拦截器
type HomeRouter ¶
type HomeRouter struct { RouteGroup // HomeRouter 本身就是一个路由分组 // contains filtered or unexported fields }
站点根目录是一个特殊的路由分组,所有其他分组都是他的子孙节点
type HttpHandler ¶
type HttpHandler func(http.HandlerFunc) http.HandlerFunc
type ResponseWrap ¶
type ResponseWrap struct { http.ResponseWriter ResData // contains filtered or unexported fields }
自定义 ResponseWriter, 对标准库的一层包裹处理,需要对返回的数据做缓存,做到更灵活的控制。 实现接口 ResponseWriter
func (*ResponseWrap) HeaderValues ¶
func (w *ResponseWrap) HeaderValues() http.Header
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*ResponseWrap) Reset ¶
func (w *ResponseWrap) Reset(res http.ResponseWriter)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*ResponseWrap) Send ¶
func (w *ResponseWrap) Send() (n int, err error)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Render才会真的往返回通道写数据,Render只执行一次
func (*ResponseWrap) SendHijack ¶
func (w *ResponseWrap) SendHijack(resStatus int, data []byte) (n int)
这个主要用于严重错误的时候,特殊状态的返回 如果还没有render,强制返回服务器错误,中断其它返回。否则啥也不做。
func (*ResponseWrap) SendHijackRedirect ¶
func (w *ResponseWrap) SendHijackRedirect(req *http.Request, resStatus int, redirectUrl string)
强制跳转
func (*ResponseWrap) Status ¶
func (w *ResponseWrap) Status() int
func (*ResponseWrap) Write ¶
func (w *ResponseWrap) Write(data []byte) (n int, err error)
最后都要通过这个函数Render所有数据 问题1: 是否要避免 double render? 答:目前不需要管这个事,调用多少次Write,就往返回流写入多少数据。double render是前段业务逻辑的问题,开发应该主动避免。
func (*ResponseWrap) WriteHeader ¶
func (w *ResponseWrap) WriteHeader(newStatus int)
Gin: 只会改变这里的w.status值,而不会改变response给客户端的状态了。(这没有多大意义,GoFast做出改变) GoFast: 没有提交之前可以无限次的改变,最终返回最后一次设置的值
func (*ResponseWrap) WriteString ¶
func (w *ResponseWrap) WriteString(s string) (n int, err error)
type Ret ¶
type Ret struct { Code int32 // 返回编码 Msg string // 文本消息 Data any // 携带数据体 Desc string // 描述,内部说明,不对外传递和显示 }
返回结构体
type RouteGroup ¶
type RouteGroup struct {
// contains filtered or unexported fields
}
func (*RouteGroup) A ¶
func (gp *RouteGroup) A(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) After ¶
func (gp *RouteGroup) After(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) AfterMatch ¶
func (gp *RouteGroup) AfterMatch(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) AfterSend ¶
func (gp *RouteGroup) AfterSend(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) All ¶
func (gp *RouteGroup) All(relPath string, hds ...CtxHandler)
Any registers a route that matches all the HTTP methods. GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
func (*RouteGroup) B ¶
func (gp *RouteGroup) B(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) Before ¶
func (gp *RouteGroup) Before(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) BeforeSend ¶
func (gp *RouteGroup) BeforeSend(hds ...CtxHandler) *RouteGroup
func (*RouteGroup) Delete ¶
func (gp *RouteGroup) Delete(relPath string, hds ...CtxHandler) *RouteItem
DELETE is a shortcut for router.Handle("DELETE", path, handle).
func (*RouteGroup) Get ¶
func (gp *RouteGroup) Get(relPath string, hds ...CtxHandler) *RouteItem
func (*RouteGroup) GetPost ¶
func (gp *RouteGroup) GetPost(relPath string, hds ...CtxHandler) (get, post *RouteItem)
特殊类型
func (*RouteGroup) Group ¶
func (gp *RouteGroup) Group(relPath string) *RouteGroup
Note:如果分组已经存在,需要报错。 或者不报错。 GoFast选择不报错,允许添加相同路径的不同分组,区别应用不同的特性
func (*RouteGroup) Handle ¶
func (gp *RouteGroup) Handle(httpMethod, relPath string, hds ...CtxHandler) *RouteItem
TODO: 有个问题,httpMethod参数没有做枚举校验,可以创建任意名称的method路由数,真要这么自由吗???
func (*RouteGroup) Head ¶
func (gp *RouteGroup) Head(relPath string, hds ...CtxHandler) *RouteItem
HEAD is a shortcut for router.Handle("HEAD", path, handle).
func (*RouteGroup) Options ¶
func (gp *RouteGroup) Options(relPath string, hds ...CtxHandler) *RouteItem
OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
func (*RouteGroup) Patch ¶
func (gp *RouteGroup) Patch(relPath string, hds ...CtxHandler) *RouteItem
PATCH is a shortcut for router.Handle("PATCH", path, handle).
func (*RouteGroup) Post ¶
func (gp *RouteGroup) Post(relPath string, hds ...CtxHandler) *RouteItem
POST is a shortcut for router.Handle("POST", path, handle).
func (*RouteGroup) Prefix ¶
func (gp *RouteGroup) Prefix() string
Prefix returns the base path of router gp. For example, if v := router.Group("/rest/n/v1/api"), v.Prefix() is "/rest/n/v1/api".
func (*RouteGroup) Put ¶
func (gp *RouteGroup) Put(relPath string, hds ...CtxHandler) *RouteItem
PUT is a shortcut for router.Handle("PUT", path, handle).
func (*RouteGroup) Static ¶
func (gp *RouteGroup) Static(relPath, root string) *RouteGroup
Static serves files from the given file system root. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler. To use the operating system's file system implementation, use :
router.Static("/static", "/var/www")
func (*RouteGroup) StaticFS ¶
func (gp *RouteGroup) StaticFS(relPath string, fs http.FileSystem) *RouteGroup
StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead. Gin by default user: gin.Dir()
func (*RouteGroup) StaticFile ¶
func (gp *RouteGroup) StaticFile(relPath, filepath string) *RouteGroup
StaticFile registers a single route in order to serve a single file of the local filesystem. router.StaticFile("favicon.ico", "./resources/favicon.ico")
type RouteItem ¶
type RouteItem struct {
// contains filtered or unexported fields
}
func (*RouteItem) A ¶
func (ri *RouteItem) A(hds ...CtxHandler) *RouteItem
func (*RouteItem) After ¶
func (ri *RouteItem) After(hds ...CtxHandler) *RouteItem
func (*RouteItem) AfterMatch ¶
func (ri *RouteItem) AfterMatch(hds ...CtxHandler) *RouteItem
路由匹配到之后,没等执行中间件就走这个逻辑,可以返回标记,中断后面的中间件
func (*RouteItem) AfterSend ¶
func (ri *RouteItem) AfterSend(hds ...CtxHandler) *RouteItem
func (*RouteItem) Attrs ¶
func (ri *RouteItem) Attrs(ra RouteAttrs) *RouteItem
RouteItemAttrs +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
func (*RouteItem) B ¶
func (ri *RouteItem) B(hds ...CtxHandler) *RouteItem
func (*RouteItem) BeforeSend ¶
func (ri *RouteItem) BeforeSend(hds ...CtxHandler) *RouteItem
type SessionKeeper ¶
Source Files ¶
- base.go
- ctx.go
- ctx_baskets.go
- ctx_handler.go
- ctx_pms.go
- ctx_pms_file.go
- ctx_pms_get.go
- ctx_pms_header.go
- ctx_render.go
- ctx_response.go
- ctx_router.go
- ctx_session.go
- fst.go
- fst_config.go
- fst_events.go
- fst_handler.go
- fst_mem.go
- fst_midware.go
- fst_router.go
- router.go
- router_attrs.go
- router_event.go
- router_group.go
- router_item.go
- tree.go
- tree_match.go
- tree_mini.go
- tree_origin.go
- tree_print.go
- utils.go