egin

package
v1.1.19 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 60 Imported by: 17

Documentation

Index

Constants

View Source
const (
	// HeaderAcceptEncoding ...
	HeaderAcceptEncoding = "Accept-Encoding"
	// HeaderContentType ...
	HeaderContentType = "Content-Type"
	// HeaderGRPCPROXYError ...
	HeaderGRPCPROXYError = "GRPC-Proxy-Error"

	// MIMEApplicationJSON ...
	MIMEApplicationJSON = "application/json"
	// MIMEApplicationJSONCharsetUTF8 ...
	MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
	// MIMEApplicationProtobuf ...
	MIMEApplicationProtobuf = "application/protobuf"
)
View Source
const (
	BestCompression    = gzip.BestCompression
	BestSpeed          = gzip.BestSpeed
	DefaultCompression = gzip.DefaultCompression
	NoCompression      = gzip.NoCompression
)
View Source
const PackageName = "server.egin"

PackageName 包名

Variables

View Source
var (
	DefaultExcludedExtentions = NewExcludedExtensions([]string{
		".png", ".gif", ".jpeg", ".jpg",
	})
	DefaultOptions = &GzipOptions{
		ExcludedExtensions: DefaultExcludedExtentions,
	}
)

Functions

func DefaultDecompressHandle added in v1.1.16

func DefaultDecompressHandle(c *gin.Context)

func GRPCProxy added in v0.5.5

func GRPCProxy(h interface{}) gin.HandlerFunc

GRPCProxy experimental

func Gzip added in v1.1.16

func Gzip(level int, options ...GzipOption) gin.HandlerFunc

Types

type Component

type Component struct {
	*gin.Engine

	Server *http.Server
	// contains filtered or unexported fields
}

Component ...

func (*Component) BuildWebsocket added in v0.5.5

func (c *Component) BuildWebsocket(opts ...WebSocketOption) *WebSocket

BuildWebsocket ..

func (*Component) GetEmbedWrapper added in v0.8.3

func (c *Component) GetEmbedWrapper() *EmbedWrapper

GetEmbedWrapper http的文件系统

func (*Component) GracefulStop

func (c *Component) GracefulStop(ctx context.Context) error

GracefulStop implements server.Component interface it will stop gin server gracefully

func (*Component) HTTPEmbedFs added in v0.8.3

func (c *Component) HTTPEmbedFs() http.FileSystem

HTTPEmbedFs http的文件系统

func (*Component) Health added in v1.1.10

func (c *Component) Health() bool

Health implements server.Component interface.

func (*Component) Info

func (c *Component) Info() *server.ServiceInfo

Info returns server info, used by governor and consumer balancer

func (*Component) Init

func (c *Component) Init() error

Init 初始化

func (*Component) Invoker added in v1.1.10

func (c *Component) Invoker(fns ...func() error)

Invoker returns server info, used by governor and consumer balancer Experimental

func (*Component) Listener added in v1.1.1

func (c *Component) Listener() net.Listener

Listener listener信息

func (*Component) Name

func (c *Component) Name() string

Name 配置名称

func (*Component) PackageName

func (c *Component) PackageName() string

PackageName 包名

func (*Component) Prepare added in v1.1.11

func (c *Component) Prepare() error

Prepare 预准备数据

func (*Component) RegisterRouteComment

func (c *Component) RegisterRouteComment(method, path, comment string)

RegisterRouteComment 注册路由注释

func (*Component) Start

func (c *Component) Start() error

Start implements server.Component interface.

func (*Component) Stop

func (c *Component) Stop() error

Stop implements server.Component interface it will terminate gin server immediately

func (*Component) Upgrade

func (c *Component) Upgrade(pattern string, ws *WebSocket, handler WebSocketFunc) gin.IRoutes

Upgrade protocol to WebSocket

type Config

type Config struct {
	Host                    string // IP地址,默认0.0.0.0
	Port                    int    // PORT端口,默认9001
	Mode                    string // gin的模式,默认是release模式
	Network                 string
	ServerReadTimeout       time.Duration // 服务端,用于读取io报文过慢的timeout,通常用于互联网网络收包过慢,如果你的go在最外层,可以使用他,默认不启用。
	ServerReadHeaderTimeout time.Duration // 服务端,用于读取io报文过慢的timeout,通常用于互联网网络收包过慢,如果你的go在最外层,可以使用他,默认不启用。
	ServerWriteTimeout      time.Duration // 服务端,用于读取io报文过慢的timeout,通常用于互联网网络收包过慢,如果你的go在最外层,可以使用他,默认不启用。
	// ServerHTTPTimout        time.Duration //  这个是HTTP包提供的,可以用于IO,或者密集型计算,做timeout处理,有一次goroutine操作,然后没走一些流程,cancel体验不好,暂时先不用
	ContextTimeout                time.Duration // 只能用于IO操作,才能触发,默认不启用
	EnableMetricInterceptor       bool          // 是否开启监控,默认开启
	EnableTraceInterceptor        bool          // 是否开启链路追踪,默认开启
	EnableLocalMainIP             bool          // 自动获取ip地址
	SlowLogThreshold              time.Duration // 服务慢日志,默认500ms
	EnableAccessInterceptor       bool          // 是否开启,记录请求数据
	EnableAccessInterceptorReq    bool          // 是否开启记录请求参数,默认不开启
	EnableAccessInterceptorRes    bool          // 是否开启记录响应参数,默认不开启
	AccessInterceptorReqResFilter string        // AccessInterceptorReq 过滤器,只有符合过滤器的请求才会记录 Req 和 Res
	EnableTrustedCustomHeader     bool          // 是否开启自定义header头,记录数据往链路后传递,默认不开启
	EnableSentinel                bool          // 是否开启限流,默认不开启
	WebsocketHandshakeTimeout     time.Duration // 握手时间
	WebsocketReadBufferSize       int           // WebsocketReadBufferSize
	WebsocketWriteBufferSize      int           // WebsocketWriteBufferSize
	EnableWebsocketCompression    bool          // 是否开通压缩
	EnableWebsocketCheckOrigin    bool          // 是否支持跨域
	EnableTLS                     bool          // 是否进入 https 模式
	TLSCertFile                   string        // https 证书
	TLSKeyFile                    string        // https 私钥
	TLSClientAuth                 string        // https 客户端认证方式默认为 NoClientCert(NoClientCert,RequestClientCert,RequireAnyClientCert,VerifyClientCertIfGiven,RequireAndVerifyClientCert)
	TLSClientCAs                  []string      // https client的ca,当需要双向认证的时候指定可以倒入自签证书
	TrustedPlatform               string        // 需要用户换成自己的CDN名字,获取客户端IP地址
	EmbedPath                     string        // 嵌入embed path数据
	EnableH2C                     bool          // 开启HTTP2

	TLSSessionCache tls.ClientSessionCache
	// contains filtered or unexported fields
}

Config HTTP config

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig ...

func (*Config) Address

func (config *Config) Address() string

Address ...

func (*Config) ClientAuthType added in v0.6.4

func (config *Config) ClientAuthType() tls.ClientAuthType

ClientAuthType 客户端auth类型

type Container

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

Container defines a component instance.

func DefaultContainer

func DefaultContainer() *Container

DefaultContainer returns an default container.

func Load

func Load(key string) *Container

Load parses container configuration from configuration provider, such as a toml file, then use the configuration to construct a component container.

func (*Container) Build

func (c *Container) Build(options ...Option) *Component

Build constructs a specific component from container.

type EmbedWrapper added in v0.8.3

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

EmbedWrapper 嵌入普通的静态资源的wrapper

func (*EmbedWrapper) Open added in v0.8.3

func (e *EmbedWrapper) Open(name string) (fs.File, error)

Open 静态资源被访问的核心逻辑

type ExcludedExtensions added in v1.1.16

type ExcludedExtensions map[string]bool

Using map for better lookup performance

func NewExcludedExtensions added in v1.1.16

func NewExcludedExtensions(extensions []string) ExcludedExtensions

func (ExcludedExtensions) Contains added in v1.1.16

func (e ExcludedExtensions) Contains(target string) bool

type ExcludedPathesRegexs added in v1.1.16

type ExcludedPathesRegexs []*regexp.Regexp

func NewExcludedPathesRegexs added in v1.1.16

func NewExcludedPathesRegexs(regexs []string) ExcludedPathesRegexs

func (ExcludedPathesRegexs) Contains added in v1.1.16

func (e ExcludedPathesRegexs) Contains(requestURI string) bool

type ExcludedPaths added in v1.1.16

type ExcludedPaths []string

func NewExcludedPaths added in v1.1.16

func NewExcludedPaths(paths []string) ExcludedPaths

func (ExcludedPaths) Contains added in v1.1.16

func (e ExcludedPaths) Contains(requestURI string) bool

type GzipOption added in v1.1.16

type GzipOption func(*GzipOptions)

func WithGzipDecompressFn added in v1.1.16

func WithGzipDecompressFn(decompressFn func(c *gin.Context)) GzipOption

func WithGzipExcludedExtensions added in v1.1.16

func WithGzipExcludedExtensions(args []string) GzipOption

func WithGzipExcludedPaths added in v1.1.16

func WithGzipExcludedPaths(args []string) GzipOption

func WithGzipExcludedPathsRegexs added in v1.1.16

func WithGzipExcludedPathsRegexs(args []string) GzipOption

type GzipOptions added in v1.1.16

type GzipOptions struct {
	ExcludedExtensions   ExcludedExtensions
	ExcludedPaths        ExcludedPaths
	ExcludedPathesRegexs ExcludedPathesRegexs
	DecompressFn         func(c *gin.Context)
}

type Option

type Option func(c *Container)

Option overrides a Container's default configuration.

func WithContextTimeout added in v1.1.1

func WithContextTimeout(timeout time.Duration) Option

WithContextTimeout 设置 context 超时时间

func WithEmbedFs added in v0.8.3

func WithEmbedFs(fs embed.FS) Option

WithEmbedFs 设置embed fs

func WithHost added in v1.1.1

func WithHost(host string) Option

WithHost 设置host

func WithListener added in v1.1.16

func WithListener(listener net.Listener) Option

func WithLogger added in v0.7.0

func WithLogger(logger *elog.Component) Option

WithLogger 设置 logger

func WithNetwork added in v1.1.1

func WithNetwork(network string) Option

WithNetwork 设置network

func WithPort added in v1.1.1

func WithPort(port int) Option

WithPort 设置port

func WithRecoveryFunc added in v1.1.6

func WithRecoveryFunc(f gin.RecoveryFunc) Option

WithRecoveryFunc 设置 recovery func

func WithSentinelBlockFallback added in v0.6.4

func WithSentinelBlockFallback(fn func(*gin.Context)) Option

WithSentinelBlockFallback 限流后的返回数据

func WithSentinelResourceExtractor added in v0.6.4

func WithSentinelResourceExtractor(fn func(*gin.Context) string) Option

WithSentinelResourceExtractor 资源命名方式

func WithServerReadHeaderTimeout added in v1.1.1

func WithServerReadHeaderTimeout(timeout time.Duration) Option

WithServerReadHeaderTimeout 设置超时时间

func WithServerReadTimeout added in v1.1.1

func WithServerReadTimeout(timeout time.Duration) Option

WithServerReadTimeout 设置超时时间

func WithServerWriteTimeout added in v1.1.1

func WithServerWriteTimeout(timeout time.Duration) Option

WithServerWriteTimeout 设置超时时间

func WithTLSSessionCache added in v0.7.0

func WithTLSSessionCache(tsc tls.ClientSessionCache) Option

WithTLSSessionCache TLS Session 缓存

func WithTrustedPlatform added in v0.7.0

func WithTrustedPlatform(trustedPlatform string) Option

WithTrustedPlatform 信任的Header头,获取客户端IP地址

type WebSocket

type WebSocket struct {
	*websocket.Upgrader
}

WebSocket ..

func (*WebSocket) Upgrade

func (ws *WebSocket) Upgrade(w http.ResponseWriter, r *http.Request, c *gin.Context, handler WebSocketFunc)

Upgrade get upgrage request

type WebSocketConn

type WebSocketConn struct {
	*websocket.Conn
	GinCtx *gin.Context
}

WebSocketConn ...

type WebSocketFunc

type WebSocketFunc func(*WebSocketConn, error)

WebSocketFunc ..

type WebSocketOption

type WebSocketOption func(*WebSocket)

WebSocketOption ..

Jump to

Keyboard shortcuts

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