egin

package
Version: v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: MIT Imports: 44 Imported by: 10

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 PackageName = "server.egin"

PackageName 包名

Variables

This section is empty.

Functions

func GRPCProxy added in v0.5.5

func GRPCProxy(h interface{}) gin.HandlerFunc

GRPCProxy experimental

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

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

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

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

func (c *Component) Name() string

Name 配置名称

func (*Component) PackageName

func (c *Component) PackageName() string

PackageName 包名

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模式
	EnableMetricInterceptor    bool          // 是否开启监控,默认开启
	EnableTraceInterceptor     bool          // 是否开启链路追踪,默认开启
	EnableLocalMainIP          bool          // 自动获取ip地址
	SlowLogThreshold           time.Duration // 服务慢日志,默认500ms
	EnableAccessInterceptor    bool          // 是否开启,记录请求数据
	EnableAccessInterceptorReq bool          // 是否开启记录请求参数,默认不开启
	EnableAccessInterceptorRes bool          // 是否开启记录响应参数,默认不开启
	EnableTrustedCustomHeader  bool          // 是否开启自定义header头,记录数据往链路后传递,默认不开启
	EnableSentinel             bool          // 是否开启限流,默认不开启
	WebsocketHandshakeTimeout  time.Duration // 握手时间
	WebsocketReadBufferSize    int
	WebsocketWriteBufferSize   int
	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,当需要双向认证的时候指定可以倒入自签证书
	// 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 容器

func DefaultContainer

func DefaultContainer() *Container

DefaultContainer 默认容器

func Load

func Load(key string) *Container

Load 加载配置key

func (*Container) Build

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

Build 构建组件

type Option

type Option func(c *Container)

Option 可选项

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 资源命名方式

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