fst

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 30 Imported by: 0

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

View Source
const (
	DebugMode   = "debug"
	DevMode     = "dev"
	TestMode    = "test"
	ProductMode = "product"
)
View Source
const (
	EBeforeBuildRoutes = "onBeforeBuildRoutes" // 开始重构路由树前
	EAfterBuildRoutes  = "onAfterBuildRoutes"  // 重构路由树后
	EReady             = "onReady"             // server 接收正式请求之前调用
	EClose             = "onClose"             // server 关闭退出之前调用
)
View Source
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.

Types

type AppHandler

type AppHandler func(gft *GoFast)

type Context

type Context struct {
	EnterTime  time.Duration  // 请求起始时间
	ResWrap    *ResponseWrap  // 被封装后的Response
	ReqRaw     *http.Request  // 原始 request
	Sess       SessionKeeper  // Session数据,数据存储部分可以自定义
	UrlParams  *routeParams   // : 或 * 对应的参数
	Pms        cst.KV         // 所有Request参数的map(queryCache + formCache)一般用于构造model对象
	CarryItems tips.CarryList // []*CarryItem,可以携带扩展的自定义数据
	PanicPet   panicHandler   // 业务逻辑异常之后的处理

	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

func (c *Context) AbortDirect(resStatus int, stream any)

强行终止处理,立即返回指定结果,不执行Render

func (*Context) AbortFai

func (c *Context) AbortFai(code int, msg string, data any)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Abort系列函数都将终止当前 handlers 的执行 立即返回错误,跳过后面的执行链

func (*Context) AbortRedirect

func (c *Context) AbortRedirect(resStatus int, redirectUrl string)

func (*Context) AbortRet added in v0.4.4

func (c *Context) AbortRet(ret *cst.Ret)

func (*Context) Bind

func (c *Context) Bind(dst any) error

add by sdx on 20210305 c.Pms 中有提交的所有数据,以KV形式存在。我们需要用这个数据源绑定任意的struct对象

func (*Context) CarryAddMsg added in v0.4.4

func (c *Context) CarryAddMsg(msg string)

添加一条消息,日志系统会打印出这些传递信息

func (*Context) CarryMsgItems added in v0.4.4

func (c *Context) CarryMsgItems() tips.CarryList

取出只作为消息传递的项

func (*Context) ClientIP

func (c *Context) ClientIP() string

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) CollectPms added in v0.4.4

func (c *Context) CollectPms() error

##这个方法很重要## 框架每次都将请求所携带的相关数据解析之后加入统一的变量c.Pms中,这样对开发人员来说只需要关注c.Pms中有无自己想要的数据, 至于数据是通过什么形式提交上来的并不那么重要。 最常见的就是GET请求URL上的参数,POST请求中req.Body携带的信息

func (*Context) ContentType

func (c *Context) ContentType() string

ContentType returns the Content-Type header of the request.

func (*Context) Fai

func (c *Context) Fai(code int, msg string, data any)

func (*Context) FaiCode

func (c *Context) FaiCode(code int)

func (*Context) FaiData

func (c *Context) FaiData(data any)

func (*Context) FaiErr

func (c *Context) FaiErr(err error)

func (*Context) FaiMsg

func (c *Context) FaiMsg(msg string)

func (*Context) FaiRet

func (c *Context) FaiRet(ret *cst.Ret)

func (*Context) File

func (c *Context) File(filepath string)

File writes the specified file into the body stream in a efficient way.

func (*Context) FormFile

func (c *Context) FormFile(name string) (*multipart.FileHeader, error)

FormFile returns the first file for the provided form key.

func (*Context) FullPath

func (c *Context) FullPath() string

func (*Context) Get

func (c *Context) Get(key string) (val any, ok bool)

func (*Context) GetBool

func (c *Context) GetBool(key string) (bool, error)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Context) GetBoolDef

func (c *Context) GetBoolDef(key string, def bool) bool

func (*Context) GetBoolMust

func (c *Context) GetBoolMust(key string) bool

func (*Context) GetDuration

func (c *Context) GetDuration(key string) (time.Duration, error)

func (*Context) GetDurationDef

func (c *Context) GetDurationDef(key string, def time.Duration) time.Duration

func (*Context) GetDurationMust

func (c *Context) GetDurationMust(key string) time.Duration

func (*Context) GetFloat32

func (c *Context) GetFloat32(key string) (float32, error)

func (*Context) GetFloat32Def

func (c *Context) GetFloat32Def(key string, def float32) float32

func (*Context) GetFloat32Must

func (c *Context) GetFloat32Must(key string) float32

func (*Context) GetFloat64

func (c *Context) GetFloat64(key string) (float64, error)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Context) GetFloat64Def

func (c *Context) GetFloat64Def(key string, def float64) float64

func (*Context) GetFloat64Must

func (c *Context) GetFloat64Must(key string) float64

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

func (*Context) GetInt

func (c *Context) GetInt(key string) (int, error)

func (*Context) GetInt16

func (c *Context) GetInt16(key string) (int16, error)

func (*Context) GetInt16Def

func (c *Context) GetInt16Def(key string, def int16) int16

func (*Context) GetInt16Must

func (c *Context) GetInt16Must(key string) int16

func (*Context) GetInt32

func (c *Context) GetInt32(key string) (int32, error)

func (*Context) GetInt32Def

func (c *Context) GetInt32Def(key string, def int32) int32

func (*Context) GetInt32Must

func (c *Context) GetInt32Must(key string) int32

func (*Context) GetInt64

func (c *Context) GetInt64(key string) (int64, error)

func (*Context) GetInt64Def

func (c *Context) GetInt64Def(key string, def int64) int64

func (*Context) GetInt64Must

func (c *Context) GetInt64Must(key string) int64

func (*Context) GetInt8

func (c *Context) GetInt8(key string) (int8, error)

func (*Context) GetInt8Def

func (c *Context) GetInt8Def(key string, def int8) int8

func (*Context) GetInt8Must

func (c *Context) GetInt8Must(key string) int8

func (*Context) GetIntDef

func (c *Context) GetIntDef(key string, def int) int

func (*Context) GetIntMust

func (c *Context) GetIntMust(key string) int

func (*Context) GetMust

func (c *Context) GetMust(key string) any

func (*Context) GetString

func (c *Context) GetString(key string) (string, error)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func (*Context) GetStringDef

func (c *Context) GetStringDef(key string, def string) string

func (*Context) GetStringMust

func (c *Context) GetStringMust(key string) string

func (*Context) GetTime

func (c *Context) GetTime(key string) (*time.Time, error)

func (*Context) GetTimeDef

func (c *Context) GetTimeDef(key string, def *time.Time) *time.Time

func (*Context) GetTimeMust

func (c *Context) GetTimeMust(key string) *time.Time

func (*Context) GetUint

func (c *Context) GetUint(key string) (uint, error)

func (*Context) GetUint16

func (c *Context) GetUint16(key string) (uint16, error)

func (*Context) GetUint16Def

func (c *Context) GetUint16Def(key string, def uint16) uint16

func (*Context) GetUint16Must

func (c *Context) GetUint16Must(key string) uint16

func (*Context) GetUint32

func (c *Context) GetUint32(key string) (uint32, error)

func (*Context) GetUint32Def

func (c *Context) GetUint32Def(key string, def uint32) uint32

func (*Context) GetUint32Must

func (c *Context) GetUint32Must(key string) uint32

func (*Context) GetUint64

func (c *Context) GetUint64(key string) (uint64, error)

func (*Context) GetUint64Def

func (c *Context) GetUint64Def(key string, def uint64) uint64

func (*Context) GetUint64Must

func (c *Context) GetUint64Must(key string) uint64

func (*Context) GetUint8

func (c *Context) GetUint8(key string) (uint8, error)

func (*Context) GetUint8Def

func (c *Context) GetUint8Def(key string, def uint8) uint8

func (*Context) GetUint8Must

func (c *Context) GetUint8Must(key string) uint8

func (*Context) GetUintDef

func (c *Context) GetUintDef(key string, def uint) uint

func (*Context) GetUintMust

func (c *Context) GetUintMust(key string) uint

func (*Context) IfSucFai added in v0.4.4

func (c *Context) IfSucFai(ifTrue bool, suc, fai any)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 自定义三目运算,返货成功或失败信息

func (*Context) IsWebsocket

func (c *Context) IsWebsocket() bool

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

func (*Context) Json

func (c *Context) Json(resStatus int, obj any)

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

func (*Context) MultipartForm

func (c *Context) MultipartForm() (*multipart.Form, error)

MultipartForm is the parsed multipart form, including file uploads.

func (*Context) Next

func (c *Context) Next()

执行下一个中间件函数

func (*Context) Panic added in v0.4.4

func (c *Context) Panic(ret any)

func (*Context) PanicCatch added in v0.4.4

func (c *Context) PanicCatch(ret any)

取出只作为消息传递的项

func (*Context) PanicIf added in v0.4.4

func (c *Context) PanicIf(ifTrue bool, ret any)

func (*Context) PanicIfErr added in v0.4.4

func (c *Context) PanicIfErr(err error, ret any)

如果有错误就引发异常,同时返回指定的结果

func (*Context) PanicString added in v0.4.4

func (c *Context) PanicString(ret string)

func (*Context) Param

func (c *Context) Param(key string) string

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

func (c *Context) PostForm(key string) string

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

func (c *Context) PostForm2(key string) (string, bool)

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

func (c *Context) PostFormArray(key string) []string

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

func (c *Context) PostFormArray2(key string) ([]string, bool)

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

func (c *Context) PostFormDef(key, defaultValue string) string

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

func (c *Context) PostFormMap(key string) map[string]string

PostFormMap returns a map for a given form key.

func (*Context) PostFormMap2

func (c *Context) PostFormMap2(key string) (map[string]string, bool)

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

func (c *Context) Query(key string) string

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

func (c *Context) Query2(key string) (string, bool)

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

func (c *Context) QueryArray(key string) []string

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

func (c *Context) QueryArray2(key string) ([]string, bool)

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

func (c *Context) QueryDef(key, defaultValue string) string

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

func (c *Context) QueryMap(key string) map[string]string

QueryMap returns a map for a given query key.

func (*Context) QueryMap2

func (c *Context) QueryMap2(key string) (map[string]string, bool)

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

func (c *Context) Render(resStatus int, r render.Render)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Render writes the response headers and calls render.Render to render data. 返回数据的接口 可以自定义扩展自己需要的Render

func (*Context) RenderTimeout

func (c *Context) RenderTimeout(resStatus int, hint any) bool

这个是为超时返回准备的特殊方法,一般不要使用

func (*Context) SaveUploadedFile

func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error

SaveUploadedFile uploads the form file to specific dst.

func (*Context) Set

func (c *Context) Set(key string, val any)

func (*Context) SetRouteTo404

func (c *Context) SetRouteTo404()

func (*Context) SetRouteTo405

func (c *Context) SetRouteTo405()

func (*Context) SetRouteToAny

func (c *Context) SetRouteToAny()

func (*Context) String

func (c *Context) String(resStatus int, format string, values ...any)

String writes the given string into the response body.

func (*Context) Suc

func (c *Context) Suc(code int, msg string, data any)

func (*Context) SucCode

func (c *Context) SucCode(code int)

func (*Context) SucData

func (c *Context) SucData(data any)

func (*Context) SucMsg

func (c *Context) SucMsg(msg string)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++

func (*Context) SucRet

func (c *Context) SucRet(ret *cst.Ret)

type CtxHandler

type CtxHandler func(ctx *Context)

type GfConfig

type GfConfig struct {
	AppName          string `v:"required"`                            // 应用名称
	ServerNo         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

func CreateServer(cfg *GfConfig) *GoFast

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 第一步:初始化一个 WebServer , 配置各种参数

func Default

func Default() *GoFast

一个快速创建Server的函数,使用默认配置参数,方便调用。 记住:使用之前一定要先调用 ReadyToListen方法。

func (*GoFast) BuildRoutes

func (gft *GoFast) BuildRoutes()

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NOTE:重构路由树。(重要!重要!重要!必须调用这个方法初始化路由树和中间件) 在不执行真正Listen的场景中,调用此函数能初始化服务器(必须要调用此函数来构造路由)

func (*GoFast) FullPath

func (gft *GoFast) FullPath(idx uint16) string

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 获取相应路由节点完整URL

func (*GoFast) GracefulShutdown

func (gft *GoFast) GracefulShutdown()

func (*GoFast) IsDebugging

func (gft *GoFast) IsDebugging() bool

是否处于Debug模式

func (*GoFast) Listen

func (gft *GoFast) Listen(addr ...string)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 第二步:启动端口监听 说明:第一步和第二步之间,需要做所有的工作,主要就是初始化参数,设置所有的路由和处理函数

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 (gft *GoFast) ProjectName() (name string)

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 (gft *GoFast) RoutePaths() []string

func (*GoFast) RoutePathsWithMethod

func (gft *GoFast) RoutePathsWithMethod() []string

func (*GoFast) RoutesLen

func (gft *GoFast) RoutesLen() uint16

func (*GoFast) ServeHTTP

func (gft *GoFast) ServeHTTP(w http.ResponseWriter, r *http.Request)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ http服务器,所有请求的入口,底层是用 goroutine 发起的一个协程任务 也就是说主线程,获取到任何请求事件(数据)之后,通过goroutine调用这个接口方法来并行处理 这里的代码就是在一个协程中运行的 Note: 1. 这是请求进来之后的第一级上下文,为了节省内存空间,第一级的拦截器通过之后,会进入第二级更丰富的Context上下文(占用内存更多)

func (*GoFast) SetMode

func (gft *GoFast) SetMode(mode string)

设置运行模式

func (*GoFast) SpecialAfter

func (gft *GoFast) SpecialAfter(hds ...CtxHandler)

func (*GoFast) SpecialBefore

func (gft *GoFast) SpecialBefore(hds ...CtxHandler)

SpecialRouteGroup

func (*GoFast) SpecialRoutePaths

func (gft *GoFast) SpecialRoutePaths() []string

func (*GoFast) SpecialRoutesLen

func (gft *GoFast) SpecialRoutesLen() uint16

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ special

func (*GoFast) UseGlobal

func (gft *GoFast) UseGlobal(inject injectFunc) *GoFast

用于封装,框架自定义一组

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 PanicFunc added in v0.4.4

type PanicFunc struct {
	Func func()
}

func (PanicFunc) Callback added in v0.4.4

func (pw PanicFunc) Callback()

type ResData

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

type ResponseWrap

type ResponseWrap struct {
	http.ResponseWriter

	ResData
	// contains filtered or unexported fields
}

自定义 ResponseWriter, 对标准库的一层包裹处理,需要对返回的数据做缓存,做到更灵活的控制。 实现接口 ResponseWriter

func (*ResponseWrap) DataSize

func (w *ResponseWrap) DataSize() int

数据长度

func (*ResponseWrap) Flush

func (w *ResponseWrap) Flush() bool

重置返回结果(没有最终response的情况下,可以重置返回内容)

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)

func (*ResponseWrap) WrittenData

func (w *ResponseWrap) WrittenData() []byte

当前已写的数据内容

type RouteAttrs

type RouteAttrs interface {
	SetRouteIndex(uint16)
}

可以为路由自定义配置属性

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

func (ri *RouteItem) Before(hds ...CtxHandler) *RouteItem

注册节点的所有事件

func (*RouteItem) BeforeSend

func (ri *RouteItem) BeforeSend(hds ...CtxHandler) *RouteItem

type SessionKeeper

type SessionKeeper interface {
	GetValues() cst.KV   // 获取当前session中的所有键值对
	Get(string) any      // 获取某个key的值
	Set(string, any)     // 设置session的一组kv值
	SetKV(cst.KV)        // cst.KV 类型的session数据
	Del(string)          // 删除某个session中的key
	Save()               // 保存session数据
	Saved() bool         // 是否已保存
	ExpireS(int32)       // 设置过期时间秒
	SidIsNew() bool      // SessionID is new?
	Sid() string         // SessionID
	Destroy()            // 销毁当前session数据
	Recreate(c *Context) // 重新创建session信息
}

实现Session存储时,处理失败就抛出异常

type UrlParam

type UrlParam struct {
	Key   string
	Value string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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