http

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

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

View Source
const (
	ErrEngineEmpty  = "engine is not init"
	ErrServerClosed = "server is closed"
)
View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	PATCH  = "PATCH"
	OPTION = "OPTION"
)
View Source
const (
	REST   = "REST"
	HTML   = "HTML"
	STRING = "STRING"
	FILE   = "FILE"
)
View Source
const (
	// CtxDone 上下文响应结束
	CtxDone = "CtxDone"
)
View Source
const (
	FushinBuf = "enableFushinBuf"
)

Variables

This section is empty.

Functions

func ModuleName

func ModuleName() string

func NewStore added in v1.1.5

func NewStore(duration time.Duration)

func PatchServerWithRegex added in v1.1.5

func PatchServerWithRegex(s *Server) *ginregex.RegexRouter

PatchServerWithRegex 对Server进行封装 后续所有的路由定义将使用正则匹配

Types

type Address

type Address struct {
	Host   string   // 监听的HOST
	Port   int      // 监听的端口
	Domain []string // 用于校验refer的域名(非指定域名会直接屏蔽请求) 绑定域名后会默认校验refer
}

type Context

type Context struct {
	*gin.Context
}

func (*Context) BeforeResponse

func (c *Context) BeforeResponse(wrapperFunc WrapperFunc)

BeforeResponse 响应前的处理

func (*Context) Response

func (c *Context) Response(t string, s int, data interface{})

Response 响应

func (*Context) ResponseAny

func (c *Context) ResponseAny(data interface{})

ResponseAny 不做类型推断返回stream

func (*Context) ResponseBad

func (c *Context) ResponseBad(t string, data interface{})

ResponseBad 错误响应500

func (*Context) ResponseByte added in v1.1.5

func (c *Context) ResponseByte(b []byte)

func (*Context) ResponseFile

func (c *Context) ResponseFile(s int, f string)

ResponseFile alias of response with type file

func (*Context) ResponseGood

func (c *Context) ResponseGood(t string, data interface{})

ResponseGood 200响应

func (*Context) ResponseHtml

func (c *Context) ResponseHtml(s int, f string)

ResponseHtml alias of response with type html

func (*Context) ResponseREST

func (c *Context) ResponseREST(s int, data interface{})

ResponseREST alias of response with type rest

func (*Context) ResponseStr

func (c *Context) ResponseStr(s int, data string)

ResponseStr alias of response with type string

type Router

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

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) GetAddr added in v1.1.5

func (s *Server) GetAddr() string

func (*Server) GetEngine added in v1.1.5

func (s *Server) GetEngine() *gin.Engine

func (*Server) GetSrv added in v1.1.13

func (s *Server) GetSrv() *http.Server

GetSrv 创建内置srv后的hook

func (*Server) GetTls added in v1.1.13

func (s *Server) GetTls() (string, string)

func (*Server) Group

func (s *Server) Group(path string, wrap ...WrapperFunc) *RouterGroup

Group 路由分组

func (*Server) Init

func (s *Server) Init()

Init 在其他方法被调用前初始化

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) ListenSmooth

func (s *Server) ListenSmooth()

ListenSmooth 平滑关闭 在注册监听signal的时候生效 默认注册CTRL+C

func (*Server) ListenTLS added in v1.1.13

func (s *Server) ListenTLS(cert, key string) error

ListenTLS SSL服务的语法糖

func (*Server) RegMiddle

func (s *Server) RegMiddle(mds ...Wrapper)

RegMiddle 注册中间件

func (*Server) RegSignals

func (s *Server) RegSignals(sigs ...os.Signal)

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

func (s *Server) Run()

Run 不处理错误版本的listen

func (*Server) RunTLS added in v1.1.13

func (s *Server) RunTLS(cert, key string)

func (*Server) SetHeaders added in v1.1.5

func (s *Server) SetHeaders(headers map[string]string)

func (*Server) Static added in v1.1.5

func (s *Server) Static(uri string, fs string, enableHTTP bool)

Static 静态伺服功能 将代理uri指向本地的fs路径下的文件 静态路由不会进入router中存储所以应该最先定义 uri 路由, fs 文件系统路径, enableHTTP 是否启动HTTP文件服务器

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 MiddleWareGzip added in v1.1.5

func MiddleWareGzip() WrapperFunc

MiddleWareGzip 使用gzip 默认等级9

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 MiddleWareLogger added in v1.1.2

func MiddleWareLogger() WrapperFunc

MiddleWareLogger 路由日志

func ToWrapperFunc added in v1.1.5

func ToWrapperFunc(handlerFunc gin.HandlerFunc) WrapperFunc

ToWrapperFunc 暴露外部使用 当需要从gin中间件转为fushin时

Jump to

Keyboard shortcuts

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