Documentation ¶
Overview ¶
Package http
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http ¶
Package http
Index ¶
- Constants
- func ModuleName() string
- func NewStore(duration time.Duration)
- func PatchServerWithRegex(s *Server) *ginregex.RegexRouter
- type Address
- type Context
- func (c *Context) BeforeResponse(wrapperFunc WrapperFunc)
- func (c *Context) Response(t string, s int, data interface{})
- func (c *Context) ResponseAny(data interface{})
- func (c *Context) ResponseBad(t string, data interface{})
- func (c *Context) ResponseByte(b []byte)
- func (c *Context) ResponseFile(s int, f string)
- func (c *Context) ResponseGood(t string, data interface{})
- func (c *Context) ResponseHtml(s int, f string)
- func (c *Context) ResponseREST(s int, data interface{})
- func (c *Context) ResponseStr(s int, data string)
- type Router
- type RouterGroup
- type Server
- func (s *Server) GetAddr() string
- func (s *Server) GetEngine() *gin.Engine
- func (s *Server) GetSrv() *http.Server
- func (s *Server) GetTls() (string, string)
- func (s *Server) Group(path string, wrap ...WrapperFunc) *RouterGroup
- func (s *Server) Init()
- func (s *Server) Listen() error
- func (s *Server) ListenSmooth()
- func (s *Server) ListenTLS(cert, key string) error
- func (s *Server) RegMiddle(mds ...Wrapper)
- func (s *Server) RegSignals(sigs ...os.Signal)
- func (s *Server) Route(method, uri string, wrap ...WrapperFunc)
- func (s *Server) RouteRegex(method, uri string, wrap ...WrapperFunc)
- func (s *Server) Run()
- func (s *Server) RunTLS(cert, key string)
- func (s *Server) SetHeaders(headers map[string]string)
- func (s *Server) Static(uri string, fs string, enableHTTP bool)
- type Wrapper
- type WrapperFunc
- func MiddleWareCache(duration time.Duration, wrapperFunc WrapperFunc) WrapperFunc
- func MiddleWareCors() WrapperFunc
- func MiddleWareFushinBuf() WrapperFunc
- func MiddleWareGzip() WrapperFunc
- func MiddleWareGzipLevel(level int, exclude []string) WrapperFunc
- func MiddleWareHeaders(headers map[string]string) WrapperFunc
- func MiddleWareLogger() WrapperFunc
- func ToWrapperFunc(handlerFunc gin.HandlerFunc) WrapperFunc
Constants ¶
const ( ErrEngineEmpty = "engine is not init" ErrServerClosed = "server is closed" )
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" PATCH = "PATCH" OPTION = "OPTION" )
const ( REST = "REST" HTML = "HTML" STRING = "STRING" FILE = "FILE" )
const (
// CtxDone 上下文响应结束
CtxDone = "CtxDone"
)
const (
FushinBuf = "enableFushinBuf"
)
Variables ¶
This section is empty.
Functions ¶
func ModuleName ¶
func ModuleName() string
func PatchServerWithRegex ¶ added in v1.1.5
func PatchServerWithRegex(s *Server) *ginregex.RegexRouter
PatchServerWithRegex 对Server进行封装 后续所有的路由定义将使用正则匹配
Types ¶
type Context ¶
func (*Context) BeforeResponse ¶
func (c *Context) BeforeResponse(wrapperFunc WrapperFunc)
BeforeResponse 响应前的处理
func (*Context) ResponseAny ¶
func (c *Context) ResponseAny(data interface{})
ResponseAny 不做类型推断返回stream
func (*Context) ResponseBad ¶
ResponseBad 错误响应500
func (*Context) ResponseByte ¶ added in v1.1.5
func (*Context) ResponseFile ¶
ResponseFile alias of response with type file
func (*Context) ResponseGood ¶
ResponseGood 200响应
func (*Context) ResponseHtml ¶
ResponseHtml alias of response with type html
func (*Context) ResponseREST ¶
ResponseREST alias of response with type rest
func (*Context) ResponseStr ¶
ResponseStr alias of response with type string
type RouterGroup ¶
type RouterGroup struct {
*gin.RouterGroup
}
type Server ¶
type Server struct { EnableLog bool // 使用内置的日志打印 默认输出到控制台 Logger log.LoggerInterface // 使用的日志记录器 默认为内置日志 Debug bool // 开启gin的debug RegSignal []os.Signal // 监听系统信号量 Address Address // 监听地址 Headers map[string]string // 自定义的Headers Copyright string // 版权所有 会以header: Copyright: xx的方式返回在响应中 MaxBodySize int // 最大请求体限制 默认1<<20 bytes ReadTimeout int // 继承http.Server WriteTimeout int // 继承http.Server IdleTimeout int // 继承http.Server // tls support Tls bool // 开启tls support Certfile string // 证书 Keyfile string // 私钥 PProf bool // 是否开启pprof 路径为"debug/pprof" // contains filtered or unexported fields }
func (*Server) Group ¶
func (s *Server) Group(path string, wrap ...WrapperFunc) *RouterGroup
Group 路由分组
func (*Server) ListenSmooth ¶
func (s *Server) ListenSmooth()
ListenSmooth 平滑关闭 在注册监听signal的时候生效 默认注册CTRL+C
func (*Server) RegSignals ¶
RegSignals 信号注册 默认为空时注册interrupt可能导致其他loop无法退出 所以仅在debug模式下注册此信号
func (*Server) Route ¶
func (s *Server) Route(method, uri string, wrap ...WrapperFunc)
Route 路由方法 不提供语法糖写法 必须指定请求方法
func (*Server) RouteRegex ¶ added in v1.1.5
func (s *Server) RouteRegex(method, uri string, wrap ...WrapperFunc)
RouteRegex 使用正则匹配路由
func (*Server) SetHeaders ¶ added in v1.1.5
type Wrapper ¶
type Wrapper struct { Name string WrapperFunc WrapperFunc }
type WrapperFunc ¶
type WrapperFunc func(c *Context)
func MiddleWareCache ¶ added in v1.1.5
func MiddleWareCache(duration time.Duration, wrapperFunc WrapperFunc) WrapperFunc
MiddleWareCache 提供基于内存的cache 默认的缓存时间为1min 需要使用NewCacheStore创建 WrapperFunc为要缓存的路由方法 更详细的使用请直接使用gin-cache
func MiddleWareCors ¶ added in v1.1.2
func MiddleWareCors() WrapperFunc
MiddleWareCors 默认的cors 允许所有跨域
func MiddleWareFushinBuf ¶ added in v1.1.5
func MiddleWareFushinBuf() WrapperFunc
MiddleWareFushinBuf 开启fushin buf 基于gob的二进制传输 仅在header开启enableFushinbuf时 或query?enableFushinbuf=true启用
func MiddleWareGzipLevel ¶ added in v1.1.5
func MiddleWareGzipLevel(level int, exclude []string) WrapperFunc
MiddleWareGzipLevel 使用gzip 按照等级压缩1-9 支持排除某些特殊接口
func MiddleWareHeaders ¶ added in v1.1.5
func MiddleWareHeaders(headers map[string]string) WrapperFunc
MiddleWareHeaders 自定义headers k-v结构 v为空时清除header
func ToWrapperFunc ¶ added in v1.1.5
func ToWrapperFunc(handlerFunc gin.HandlerFunc) WrapperFunc
ToWrapperFunc 暴露外部使用 当需要从gin中间件转为fushin时