Documentation
¶
Overview ¶
Package ginmiddleware 基于gin的web框架封装
Index ¶
- func AddLocalWWW(relativePath, root string, r *gin.Engine, src *embed.FS) error
- func BasicAuth(accountpairs ...string) gin.HandlerFunc
- func Blacklist(excludePath ...string) gin.HandlerFunc
- func CFConnectingIP() gin.HandlerFunc
- func CheckRequired(params ...string) gin.HandlerFunc
- func CheckSecurityCode(codeType string, codeRange int) gin.HandlerFunc
- func Delay() gin.HandlerFunc
- func GetClientAddr(c *gin.Context) string
- func GetClientIP(c *gin.Context) string
- func GetClientIPPort(c *gin.Context) (string, string)
- func GetSocketTimeout() time.Duration
- func HideParams(params ...string) gin.HandlerFunc
- func ListenAndServe(port int, h *gin.Engine) error
- func ListenAndServeTLS(port int, h *gin.Engine, certfile, keyfile string) error
- func ListenAndServeWithOption(opts ...Opts)
- func LiteEngine(w io.Writer, hosts ...string) *gin.Engine
- func LogToWriter(out io.Writer, skippath ...string) gin.HandlerFunc
- func Page403(c *gin.Context)
- func Page404(c *gin.Context)
- func Page404Code(c *gin.Context)
- func Page404Rand(c *gin.Context)
- func Page405(c *gin.Context)
- func PageAbort(c *gin.Context)
- func PageDefault(c *gin.Context)
- func PageDev(c *gin.Context)
- func PageEmpty(c *gin.Context)
- func RateLimit(r, b int) gin.HandlerFunc
- func ReadCacheJSON(mydb db.SQLInterface) gin.HandlerFunc
- func ReadCachePB2(mydb db.SQLInterface) gin.HandlerFunc
- func ReadParams() gin.HandlerFunc
- func Recovery() gin.HandlerFunc
- func SecurityHeadersMiddleware() gin.HandlerFunc
- func TLSRedirect() gin.HandlerFunc
- func XForwardedIP() gin.HandlerFunc
- type Opt
- type Opts
- func OptDebug(d bool) Opts
- func OptEngine(r *gin.Engine) Opts
- func OptEngineFunc(f func() *gin.Engine) Opts
- func OptHTTP(s string) Opts
- func OptHTTPS(s string, t *tls.Config) Opts
- func OptHTTPSFromFile(s, certFile, keyFile string) Opts
- func OptHosts(hosts ...string) Opts
- func OptIdleTimeout(t time.Duration) Opts
- func OptReadTimeout(t time.Duration) Opts
- func OptWriteTimeout(t time.Duration) Opts
- func OptWriter(w io.Writer) Opts
- type ServiceOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLocalWWW ¶
AddLocalWWW serves static files from either a local directory or an embedded filesystem on the specified Gin engine. If src is nil, it serves files from the local directory specified by root using gin.Engine.Static. If src is not nil, it serves files from the embedded filesystem under the given root using gin.Engine.StaticFS. The relativePath parameter specifies the URL path at which the files will be served. Returns an error if any required parameter is missing or if the embedded filesystem cannot be accessed.
func BasicAuth ¶
func BasicAuth(accountpairs ...string) gin.HandlerFunc
BasicAuth 返回basicauth信息
使用`username:password`格式提交
func CheckSecurityCode ¶
func CheckSecurityCode(codeType string, codeRange int) gin.HandlerFunc
CheckSecurityCode 校验安全码 codeType: 安全码更新周期,h: 每小时更新,m: 每分钟更新 codeRange: 安全码容错范围(分钟)
func GetClientAddr ¶
GetClientAddr 返回用于连接/显示的地址字符串。 如果有端口则返回 "ip:port"(IPv6 会自动加方括号),否则返回 ip。
func GetClientIP ¶
func GetClientIPPort ¶
GetClientIPPort 从 gin.Context 中解析请求来源的实际 IP 和端口。 优先使用常见代理头(X-Forwarded-For, X-Real-IP, CF-Connecting-IP, Forwarded), 若头中包含多个值取第一个;若头只含 IP(无端口)则端口为空。 返回 ip (不带方括号) 和 port(可能为空)。
func ListenAndServe ¶
ListenAndServe 启用监听 port:端口号 h: http.hander, like gin.New()
func ListenAndServeTLS ¶
ListenAndServeTLS 启用TLS监听 port:端口号 h: http.hander, like gin.New() certfile: cert file path keyfile: key file path clientca: 客户端根证书用于验证客户端合法性
func ListenAndServeWithOption ¶
func ListenAndServeWithOption(opts ...Opts)
ListenAndServeWithOption 启动服务
func LogToWriter ¶
func LogToWriter(out io.Writer, skippath ...string) gin.HandlerFunc
LogToWriter LogToWriter
func Page404Rand ¶
func RateLimit ¶
func RateLimit(r, b int) gin.HandlerFunc
RateLimit 限流器,基于uber-go
r: 每秒可访问次数,1-100 b: 缓冲区大小
func SecurityHeadersMiddleware ¶
func SecurityHeadersMiddleware() gin.HandlerFunc
Types ¶
type Opts ¶
type Opts func(opt *Opt)
func OptEngineFunc ¶
func OptHTTPSFromFile ¶
func OptIdleTimeout ¶
func OptReadTimeout ¶
func OptWriteTimeout ¶
type ServiceOption ¶
type ServiceOption struct {
EngineFunc func() *gin.Engine
Engine *gin.Engine
Hosts []string
CertFile string
KeyFile string
LogFile string
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
HTTPPort string
HTTPSPort string
LogDays int
Debug bool
}
ServiceOption 通用化http框架