gateway

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTP2MaxConcurrentStreams  = 250     // 默认最大并发流数
	DefaultHTTP2MaxReadFrameSize      = 1 << 20 // 默认最大读取帧大小 (1MB)
	DefaultHTTP2InitialWindowSize     = 1 << 20 // 默认初始窗口大小 (1MB)
	DefaultHTTP2InitialConnWindowSize = 1 << 21 // 默认初始连接窗口大小 (2MB)
)

HTTP/2 默认配置常量

Variables

This section is empty.

Functions

func GenerateDefaultJSON

func GenerateDefaultJSON() (string, error)

GenerateDefaultJSON 生成默认Gateway配置的JSON

func GenerateDefaultYAML

func GenerateDefaultYAML() (string, error)

GenerateDefaultYAML 生成默认Gateway配置的YAML

func GetExtensionAs

func GetExtensionAs[T types.Convertible](c *Gateway, key string) (T, bool)

GetExtensionAs 获取指定类型的扩展配置(泛型版本) 使用 go-toolbox 的 convert.MustConvertTo 自动进行类型转换

支持的类型:

  • string, bool
  • int, int8, int16, int32, int64
  • uint, uint8, uint16, uint32, uint64
  • float32, float64
  • []byte, map[string]any, []any

示例:

str, ok := GetExtensionAs[string](gw, "api-key")
num, ok := GetExtensionAs[int](gw, "max-retry")
flag, ok := GetExtensionAs[bool](gw, "enabled")

Types

type ClientAuthType

type ClientAuthType string

ClientAuthType 客户端认证类型枚举

const (
	NoClientCert               ClientAuthType = "NoClientCert"               // 不需要客户端证书
	RequestClientCert          ClientAuthType = "RequestClientCert"          // 请求客户端证书(可选)
	RequireAnyClientCert       ClientAuthType = "RequireAnyClientCert"       // 要求任意客户端证书
	VerifyClientCertIfGiven    ClientAuthType = "VerifyClientCertIfGiven"    // 如果提供则验证客户端证书
	RequireAndVerifyClientCert ClientAuthType = "RequireAndVerifyClientCert" // 要求并验证客户端证书
)

func (ClientAuthType) ToTLSClientAuth

func (c ClientAuthType) ToTLSClientAuth() tls.ClientAuthType

ToTLSClientAuth 将 ClientAuthType 转换为 tls.ClientAuthType

type FieldSourceKeys

type FieldSourceKeys struct {
	Header string
	Query  string
	Cookie string
}

FieldSourceKeys 存储单个字段的所有来源 key(header / query / cookie)

type GRPC

type GRPC struct {
	Server  *GRPCServer            `mapstructure:"server" yaml:"server" json:"server"`    // GRPC服务端配置
	Clients map[string]*GRPCClient `mapstructure:"clients" yaml:"clients" json:"clients"` // GRPC客户端配置(key为服务名)
}

GRPC GRPC服务配置(包含服务端和多个客户端)

func DefaultGRPC

func DefaultGRPC() *GRPC

DefaultGRPC 创建默认GRPC配置

func (*GRPC) AddClient

func (g *GRPC) AddClient(name string, client *GRPCClient) *GRPC

AddClient 添加GRPC客户端配置

func (*GRPC) Clone

func (g *GRPC) Clone() internal.Configurable

Clone 返回配置的副本

func (*GRPC) Get

func (g *GRPC) Get() interface{}

Get 返回配置接口

func (*GRPC) GetClient

func (g *GRPC) GetClient(name string) *GRPCClient

GetClient 获取GRPC客户端配置

func (*GRPC) Set

func (g *GRPC) Set(data interface{})

Set 设置配置数据

func (*GRPC) Validate

func (g *GRPC) Validate() error

Validate 验证配置

type GRPCClient

type GRPCClient struct {
	ServiceName           string           `mapstructure:"service-name" yaml:"service-name" json:"serviceName"`                                   // 服务名称
	Endpoints             []string         `mapstructure:"endpoints" yaml:"endpoints" json:"endpoints"`                                           // 服务端点列表
	Network               string           `mapstructure:"network" yaml:"network" json:"network"`                                                 // 网络类型 (tcp, tcp4, tcp6, unix)
	MaxRecvMsgSize        int              `mapstructure:"max-recv-msg-size" yaml:"max-recv-msg-size" json:"maxRecvMsgSize"`                      // 最大接收消息大小(字节)
	MaxSendMsgSize        int              `mapstructure:"max-send-msg-size" yaml:"max-send-msg-size" json:"maxSendMsgSize"`                      // 最大发送消息大小(字节)
	KeepaliveTime         int              `mapstructure:"keepalive-time" yaml:"keepalive-time" json:"keepaliveTime"`                             // Keepalive时间(秒)
	KeepaliveTimeout      int              `mapstructure:"keepalive-timeout" yaml:"keepalive-timeout" json:"keepaliveTimeout"`                    // Keepalive超时(秒)
	ConnectionTimeout     int              `mapstructure:"connection-timeout" yaml:"connection-timeout" json:"connectionTimeout"`                 // 连接超时(秒)
	RetryTimes            int              `mapstructure:"retry-times" yaml:"retry-times" json:"retryTimes"`                                      // 重试次数
	EnableLoadBalance     bool             `mapstructure:"enable-load-balance" yaml:"enable-load-balance" json:"enableLoadBalance"`               // 是否启用负载均衡
	LoadBalancePolicy     string           `mapstructure:"load-balance-policy" yaml:"load-balance-policy" json:"loadBalancePolicy"`               // 负载均衡策略
	EnableBreaker         bool             `mapstructure:"enable-breaker" yaml:"enable-breaker" json:"enableBreaker"`                             // 是否启用客户端熔断(默认关闭,未启用时拦截器不入链)
	BreakerKeyMode        string           `mapstructure:"breaker-key-mode" yaml:"breaker-key-mode" json:"breakerKeyMode"`                        // 客户端熔断键粒度 (target_method / target / method),非法值由使用方回落默认
	EnableTLS             bool             `mapstructure:"enable-tls" yaml:"enable-tls" json:"enableTls"`                                         // 是否启用TLS
	TLSCertFile           string           `mapstructure:"tls-cert-file" yaml:"tls-cert-file" json:"tlsCertFile"`                                 // TLS证书文件
	TLSKeyFile            string           `mapstructure:"tls-key-file" yaml:"tls-key-file" json:"tlsKeyFile"`                                    // TLS密钥文件
	TLSCAFile             string           `mapstructure:"tls-ca-file" yaml:"tls-ca-file" json:"tlsCaFile"`                                       // TLS CA文件
	InitialWindowSize     int32            `mapstructure:"initial-window-size" yaml:"initial-window-size" json:"initialWindowSize"`               // HTTP/2 初始窗口大小(字节)
	InitialConnWindowSize int32            `mapstructure:"initial-conn-window-size" yaml:"initial-conn-window-size" json:"initialConnWindowSize"` // HTTP/2 初始连接窗口大小(字节)
	WaitForReady          bool             `mapstructure:"wait-for-ready" yaml:"wait-for-ready" json:"waitForReady"`                              // 是否等待连接就绪
	EnableCompression     bool             `mapstructure:"enable-compression" yaml:"enable-compression" json:"enableCompression"`                 // 是否启用压缩
	CompressionType       GRPCCompressType `mapstructure:"compression-type" yaml:"compression-type" json:"compressionType"`                       // 压缩算法类型 (gzip, snappy, zstd)
}

GRPCClient GRPC客户端配置

func DefaultGRPCClient

func DefaultGRPCClient(serviceName string, endpoints []string) *GRPCClient

DefaultGRPCClient 创建默认GRPC客户端配置

func (*GRPCClient) AddEndpoint

func (g *GRPCClient) AddEndpoint(endpoint string) *GRPCClient

AddEndpoint 添加服务端点

func (*GRPCClient) Clone

func (g *GRPCClient) Clone() *GRPCClient

Clone 返回GRPC客户端配置的副本

func (*GRPCClient) DisableClientBreaker

func (g *GRPCClient) DisableClientBreaker() *GRPCClient

DisableClientBreaker 禁用客户端熔断

func (*GRPCClient) DisableClientCompression

func (g *GRPCClient) DisableClientCompression() *GRPCClient

DisableClientCompression 禁用客户端压缩

func (*GRPCClient) EnableClientBreaker

func (g *GRPCClient) EnableClientBreaker(keyMode string) *GRPCClient

EnableClientBreaker 启用客户端熔断 keyMode 为空时保留当前值(默认 target_method),合法值 target_method / target / method 本包只存字符串,合法性校验留给使用方:go-config 不能依赖 go-rpc-gateway(会成环)

func (*GRPCClient) EnableClientCompression

func (g *GRPCClient) EnableClientCompression() *GRPCClient

EnableClientCompression 启用客户端压缩

func (*GRPCClient) EnableLoadBalancing

func (g *GRPCClient) EnableLoadBalancing(policy string) *GRPCClient

EnableLoadBalancing 启用负载均衡

func (*GRPCClient) Validate

func (g *GRPCClient) Validate() error

Validate 验证GRPC客户端配置

func (*GRPCClient) WithClientCompression

func (g *GRPCClient) WithClientCompression(compressType GRPCCompressType) *GRPCClient

WithClientCompression 设置客户端压缩配置

func (*GRPCClient) WithConnectionTimeout

func (g *GRPCClient) WithConnectionTimeout(timeout int) *GRPCClient

WithConnectionTimeout 设置连接超时

func (*GRPCClient) WithEndpoints

func (g *GRPCClient) WithEndpoints(endpoints []string) *GRPCClient

WithEndpoints 设置服务端点

func (*GRPCClient) WithHTTP2WindowSize

func (g *GRPCClient) WithHTTP2WindowSize(initialWindow, connWindow int32) *GRPCClient

WithHTTP2WindowSize 设置 HTTP/2 窗口大小(优化多路复用性能)

func (*GRPCClient) WithNetwork

func (g *GRPCClient) WithNetwork(network string) *GRPCClient

WithNetwork 设置网络类型

func (*GRPCClient) WithRetry

func (g *GRPCClient) WithRetry(retryTimes int) *GRPCClient

WithRetry 设置重试次数

func (*GRPCClient) WithTLS

func (g *GRPCClient) WithTLS(certFile, keyFile, caFile string) *GRPCClient

WithTLS 设置TLS配置

func (*GRPCClient) WithWaitForReady

func (g *GRPCClient) WithWaitForReady(wait bool) *GRPCClient

WithWaitForReady 设置是否等待连接就绪

type GRPCCompressType

type GRPCCompressType string

GRPCCompressType GRPC压缩算法类型

const (
	GRPCCompressGzip   GRPCCompressType = "gzip"   // Gzip压缩
	GRPCCompressSnappy GRPCCompressType = "snappy" // Snappy压缩(高速度)
	GRPCCompressZstd   GRPCCompressType = "zstd"   // Zstandard压缩(高压缩率)
)

func (GRPCCompressType) String

func (c GRPCCompressType) String() string

String 实现 Stringer 接口,返回压缩算法类型的字符串表示

type GRPCServer

type GRPCServer struct {
	Enable             bool             `mapstructure:"enable" yaml:"enable" json:"enable"`                                         // 是否启用GRPC服务
	Host               string           `mapstructure:"host" yaml:"host" json:"host"`                                               // 主机地址
	Port               int              `mapstructure:"port" yaml:"port" json:"port"`                                               // 端口
	Network            string           `mapstructure:"network" yaml:"network" json:"network"`                                      // 网络类型 (tcp, tcp4, tcp6, unix)
	MaxRecvMsgSize     int              `mapstructure:"max-recv-msg-size" yaml:"max-recv-msg-size" json:"maxRecvMsgSize"`           // 最大接收消息大小(字节)
	MaxSendMsgSize     int              `mapstructure:"max-send-msg-size" yaml:"max-send-msg-size" json:"maxSendMsgSize"`           // 最大发送消息大小(字节)
	KeepaliveTime      int              `mapstructure:"keepalive-time" yaml:"keepalive-time" json:"keepaliveTime"`                  // Keepalive时间(秒)
	KeepaliveTimeout   int              `mapstructure:"keepalive-timeout" yaml:"keepalive-timeout" json:"keepaliveTimeout"`         // Keepalive超时(秒)
	ConnectionTimeout  int              `mapstructure:"connection-timeout" yaml:"connection-timeout" json:"connectionTimeout"`      // 连接超时(秒)
	EnableReflection   bool             `mapstructure:"enable-reflection" yaml:"enable-reflection" json:"enableReflection"`         // 是否启用反射
	EnableProtobufResp bool             `mapstructure:"enable-protobuf-resp" yaml:"enable-protobuf-resp" json:"enableProtobufResp"` // 是否启用protobuf格式响应(grpc-gateway场景下默认返回JSON,开启后返回原始protobuf)
	EnableCompression  bool             `mapstructure:"enable-compression" yaml:"enable-compression" json:"enableCompression"`      // 是否启用压缩
	CompressionType    GRPCCompressType `mapstructure:"compression-type" yaml:"compression-type" json:"compressionType"`            // 压缩算法类型 (gzip, snappy, zstd)
	CompressionLevel   int              `mapstructure:"compression-level" yaml:"compression-level" json:"compressionLevel"`         // 压缩级别 (gzip: 1-9, zstd: 1-22, snappy: 忽略此值)
	MinCompressSize    int              `mapstructure:"min-compress-size" yaml:"min-compress-size" json:"minCompressSize"`          // 最小压缩大小(字节),小于此大小不压缩
	Endpoint           string           `mapstructure:"-" yaml:"-" json:""`                                                         // 完整的服务端点地址(自动计算)
}

GRPCServer GRPC服务端配置

func DefaultGRPCServer

func DefaultGRPCServer() *GRPCServer

DefaultGRPCServer 创建默认GRPC服务端配置

func (*GRPCServer) AfterLoad

func (g *GRPCServer) AfterLoad() error

AfterLoad GRPC Server 配置加载后的钩子 - 计算 Endpoint

func (*GRPCServer) BeforeLoad

func (g *GRPCServer) BeforeLoad() error

BeforeLoad GRPC Server 配置加载前的钩子

func (*GRPCServer) Clone

func (g *GRPCServer) Clone() *GRPCServer

Clone 返回GRPC服务端配置的副本

func (*GRPCServer) DisableCompressionService

func (g *GRPCServer) DisableCompressionService() *GRPCServer

DisableCompressionService 禁用压缩

func (*GRPCServer) DisableProtobufResponse

func (g *GRPCServer) DisableProtobufResponse() *GRPCServer

DisableProtobufResponse 禁用protobuf格式响应(返回JSON)

func (*GRPCServer) DisableReflectionService

func (g *GRPCServer) DisableReflectionService() *GRPCServer

DisableReflectionService 禁用反射服务

func (*GRPCServer) EnableCompressionService

func (g *GRPCServer) EnableCompressionService() *GRPCServer

EnableCompressionService 启用压缩

func (*GRPCServer) EnableProtobufResponse

func (g *GRPCServer) EnableProtobufResponse() *GRPCServer

EnableProtobufResponse 启用protobuf格式响应

func (*GRPCServer) EnableReflectionService

func (g *GRPCServer) EnableReflectionService() *GRPCServer

EnableReflectionService 启用反射服务

func (*GRPCServer) GetEndpoint

func (g *GRPCServer) GetEndpoint() string

GetEndpoint 获取GRPC服务端点地址

func (*GRPCServer) Validate

func (g *GRPCServer) Validate() error

Validate 验证GRPC服务端配置

func (*GRPCServer) WithCompression

func (g *GRPCServer) WithCompression(compressType GRPCCompressType, level, minCompressSize int) *GRPCServer

WithCompression 设置压缩配置

func (*GRPCServer) WithCompressionLevel

func (g *GRPCServer) WithCompressionLevel(level int) *GRPCServer

WithCompressionLevel 设置压缩级别

func (*GRPCServer) WithCompressionType

func (g *GRPCServer) WithCompressionType(compressType GRPCCompressType) *GRPCServer

WithCompressionType 设置压缩算法类型

func (*GRPCServer) WithHost

func (g *GRPCServer) WithHost(host string) *GRPCServer

WithHost 设置主机地址

func (*GRPCServer) WithKeepalive

func (g *GRPCServer) WithKeepalive(time, timeout int) *GRPCServer

WithKeepalive 设置Keepalive配置

func (*GRPCServer) WithMaxMsgSize

func (g *GRPCServer) WithMaxMsgSize(maxRecv, maxSend int) *GRPCServer

WithMaxMsgSize 设置最大消息大小

func (*GRPCServer) WithMinCompressSize

func (g *GRPCServer) WithMinCompressSize(size int) *GRPCServer

WithMinCompressSize 设置最小压缩大小

func (*GRPCServer) WithPort

func (g *GRPCServer) WithPort(port int) *GRPCServer

WithPort 设置端口

type Gateway

type Gateway struct {
	ModuleName     string                       `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`             // 模块名称
	Name           string                       `mapstructure:"name" yaml:"name" json:"name"`                                 // 网关名称
	Enabled        bool                         `mapstructure:"enabled" yaml:"enabled" json:"enabled"`                        // 是否启用网关
	Debug          bool                         `mapstructure:"debug" yaml:"debug" json:"debug"`                              // 是否启用调试模式
	Version        string                       `mapstructure:"version" yaml:"version" json:"version"`                        // 版本号
	Environment    string                       `mapstructure:"environment" yaml:"environment" json:"environment"`            // 环境 (dev, test, prod)
	BuildTime      string                       `mapstructure:"build-time" yaml:"build-time" json:"buildTime"`                // 构建时间
	BuildUser      string                       `mapstructure:"build-user" yaml:"build-user" json:"buildUser"`                // 构建用户
	GoVersion      string                       `mapstructure:"go-version" yaml:"go-version" json:"goVersion"`                // Go版本
	GitCommit      string                       `mapstructure:"git-commit" yaml:"git-commit" json:"gitCommit"`                // Git提交哈希
	GitBranch      string                       `mapstructure:"git-branch" yaml:"git-branch" json:"gitBranch"`                // Git分支
	GitTag         string                       `mapstructure:"git-tag" yaml:"git-tag" json:"gitTag"`                         // Git标签
	JSON           *JSON                        `mapstructure:"json" yaml:"json" json:"json"`                                 // JSON序列化配置
	HTTPServer     *HTTPServer                  `mapstructure:"http" yaml:"http" json:"http"`                                 // HTTP服务器配置(主监听器)
	Listeners      []*Listener                  `mapstructure:"listeners" yaml:"listeners" json:"listeners"`                  // 命名监听器列表(支持多端口,如 Ops/Tenant 分离)
	GRPC           *GRPC                        `mapstructure:"grpc" yaml:"grpc" json:"grpc"`                                 // GRPC配置
	Cache          *cache.Cache                 `mapstructure:"cache" yaml:"cache" json:"cache"`                              // 缓存配置(包含Redis)
	Database       *database.Database           `mapstructure:"database" yaml:"database" json:"database"`                     // 数据库统一配置
	ClickHouse     *tsdb.ClickHouse             `mapstructure:"clickhouse" yaml:"clickhouse" json:"clickhouse"`               // ClickHouse数据库配置
	Etcd           *etcd.Etcd                   `mapstructure:"etcd" yaml:"etcd" json:"etcd"`                                 // Etcd配置
	Kafka          *kafka.Kafka                 `mapstructure:"kafka" yaml:"kafka" json:"kafka"`                              // Kafka配置
	Mqtt           *queue.Mqtt                  `mapstructure:"mqtt" yaml:"mqtt" json:"mqtt"`                                 // MQTT配置
	Nats           *queue.Nats                  `mapstructure:"nats" yaml:"nats" json:"nats"`                                 // NATS配置
	Elasticsearch  *elasticsearch.Elasticsearch `mapstructure:"elasticsearch" yaml:"elasticsearch" json:"elasticsearch"`      // Elasticsearch配置
	Smtp           *smtp.Smtp                   `mapstructure:"smtp" yaml:"smtp" json:"smtp"`                                 // SMTP邮件服务配置
	Health         *health.Health               `mapstructure:"health" yaml:"health" json:"health"`                           // 健康检查配置
	Monitoring     *monitoring.Monitoring       `mapstructure:"monitoring" yaml:"monitoring" json:"monitoring"`               // 监控配置
	Security       *security.Security           `mapstructure:"security" yaml:"security" json:"security"`                     // 安全配置
	RequestContext *RequestContext              `mapstructure:"request-context" yaml:"request-context" json:"requestContext"` // 统一请求提取配置
	Middleware     *middleware.Middleware       `mapstructure:"middleware" yaml:"middleware" json:"middleware"`               // 中间件配置
	CORS           *cors.Cors                   `mapstructure:"cors" yaml:"cors" json:"cors"`                                 // CORS配置
	JWT            *jwt.JWT                     `mapstructure:"jwt" yaml:"jwt" json:"jwt"`                                    // JWT配置
	Swagger        *swagger.Swagger             `mapstructure:"swagger" yaml:"swagger" json:"swagger"`                        // Swagger配置
	Banner         *banner.Banner               `mapstructure:"banner" yaml:"banner" json:"banner"`                           // Banner配置
	RateLimit      *ratelimit.RateLimit         `mapstructure:"rate-limit" yaml:"rate-limit" json:"rateLimit"`                // 限流配置
	WSC            *wsc.WSC                     `mapstructure:"wsc" yaml:"wsc" json:"wsc"`                                    // WebSocket通信配置
	Jobs           *jobs.Jobs                   `mapstructure:"jobs" yaml:"jobs" json:"jobs"`                                 // Job调度配置
	Extensions     map[string]any               `mapstructure:"extensions" yaml:"extensions" json:"extensions"`               // 扩展配置字段,供第三方自定义使用
}

Gateway网关统一配置

func Default

func Default() *Gateway

Default 创建默认Gateway配置

func (*Gateway) AddJobTask

func (c *Gateway) AddJobTask(name string, task jobs.TaskCfg) *Gateway

AddJobTask 添加 Job 任务

func (*Gateway) AddListener

func (c *Gateway) AddListener(listener *Listener) *Gateway

AddListener 添加命名监听器

func (*Gateway) Clone

func (c *Gateway) Clone() internal.Configurable

Clone 返回配置的副本

func (*Gateway) DeleteExtension

func (c *Gateway) DeleteExtension(key string) *Gateway

DeleteExtension 删除扩展配置

func (*Gateway) Disable

func (c *Gateway) Disable() *Gateway

Disable 禁用网关

func (*Gateway) DisableJobTask

func (c *Gateway) DisableJobTask(name string) *Gateway

DisableJobTask 禁用指定 Job 任务

func (*Gateway) Enable

func (c *Gateway) Enable() *Gateway

Enable 启用网关

func (*Gateway) EnableBanner

func (c *Gateway) EnableBanner() *Gateway

EnableBanner 启用Banner

func (*Gateway) EnableHealth

func (c *Gateway) EnableHealth() *Gateway

EnableHealth 启用健康检查

func (*Gateway) EnableJob

func (c *Gateway) EnableJob() *Gateway

EnableJob 启用 Job 调度

func (*Gateway) EnableJobTask

func (c *Gateway) EnableJobTask(name string) *Gateway

EnableJobTask 启用指定 Job 任务

func (*Gateway) EnableMiddleware

func (c *Gateway) EnableMiddleware() *Gateway

EnableMiddleware 启用中间件

func (*Gateway) EnableMonitoring

func (c *Gateway) EnableMonitoring() *Gateway

EnableMonitoring 启用监控

func (*Gateway) EnableSwagger

func (c *Gateway) EnableSwagger() *Gateway

EnableSwagger 启用Swagger

func (*Gateway) EnableTLS

func (c *Gateway) EnableTLS() *Gateway

EnableTLS 启用TLS

func (*Gateway) EnableWSC

func (c *Gateway) EnableWSC() *Gateway

EnableWSC 启用 WebSocket 通信

func (*Gateway) Get

func (c *Gateway) Get() any

Get 返回配置接口

func (*Gateway) GetAllExtensions

func (c *Gateway) GetAllExtensions() map[string]any

GetAllExtensions 获取所有扩展配置(深拷贝副本)

func (*Gateway) GetExtension

func (c *Gateway) GetExtension(key string) (any, bool)

GetExtension 获取扩展配置

func (*Gateway) GetExtensionMap

func (c *Gateway) GetExtensionMap(key string) (map[string]any, bool)

GetExtensionMap 获取 map 类型的扩展配置

func (*Gateway) GetListener

func (c *Gateway) GetListener(name string) *Listener

GetListener 按名称获取监听器

func (*Gateway) HasExtension

func (c *Gateway) HasExtension(key string) bool

HasExtension 检查是否存在指定的扩展配置

func (*Gateway) IsEnabled

func (c *Gateway) IsEnabled() bool

IsEnabled 检查是否启用

func (*Gateway) Set

func (c *Gateway) Set(data any)

Set 设置配置数据

func (*Gateway) SetExtension

func (c *Gateway) SetExtension(key string, value any) *Gateway

SetExtension 设置扩展配置

func (*Gateway) ToJSON

func (c *Gateway) ToJSON() (string, error)

ToJSON 导出Gateway配置为JSON格式

func (*Gateway) ToYAML

func (c *Gateway) ToYAML() (string, error)

ToYAML 导出Gateway配置为YAML格式

func (*Gateway) Validate

func (c *Gateway) Validate() error

Validate 验证配置

func (*Gateway) WithBanner

func (c *Gateway) WithBanner(enabled bool, title, description, author, email, website string) *Gateway

WithBanner 设置Banner配置

func (*Gateway) WithCORS

func (c *Gateway) WithCORS(cfg *cors.Cors) *Gateway

WithCORS 设置CORS配置

func (*Gateway) WithDebug

func (c *Gateway) WithDebug(debug bool) *Gateway

WithDebug 设置调试模式

func (*Gateway) WithEnabled

func (c *Gateway) WithEnabled(enabled bool) *Gateway

WithEnabled 设置是否启用网关

func (*Gateway) WithEnvironment

func (c *Gateway) WithEnvironment(environment string) *Gateway

WithEnvironment 设置环境

func (*Gateway) WithHealth

func (c *Gateway) WithHealth(cfg *health.Health) *Gateway

WithHealth 设置健康检查配置

func (*Gateway) WithJWT

func (c *Gateway) WithJWT(cfg *jwt.JWT) *Gateway

WithJWT 设置JWT配置

func (*Gateway) WithJob

func (c *Gateway) WithJob(cfg *jobs.Jobs) *Gateway

WithJob 设置 Job 调度配置

func (*Gateway) WithListeners

func (c *Gateway) WithListeners(listeners []*Listener) *Gateway

WithListeners 设置命名监听器列表

func (*Gateway) WithMiddleware

func (c *Gateway) WithMiddleware(cfg *middleware.Middleware) *Gateway

WithMiddleware 设置中间件配置

func (*Gateway) WithModuleName

func (c *Gateway) WithModuleName(moduleName string) *Gateway

WithModuleName 设置模块名称

func (*Gateway) WithMonitoring

func (c *Gateway) WithMonitoring(cfg *monitoring.Monitoring) *Gateway

WithMonitoring 设置监控配置

func (*Gateway) WithName

func (c *Gateway) WithName(name string) *Gateway

WithName 设置网关名称

func (*Gateway) WithRequestContext

func (c *Gateway) WithRequestContext(cfg *RequestContext) *Gateway

WithRequestContext 设置统一请求提取配置

func (*Gateway) WithSecurity

func (c *Gateway) WithSecurity(cfg *security.Security) *Gateway

WithSecurity 设置安全配置

func (*Gateway) WithServer

func (c *Gateway) WithServer(host string, port int) *Gateway

WithServer 设置服务器配置

func (*Gateway) WithSwagger

func (c *Gateway) WithSwagger(cfg *swagger.Swagger) *Gateway

WithSwagger 设置Swagger配置

func (*Gateway) WithTLS

func (c *Gateway) WithTLS(enabled bool, certFile, keyFile, caFile string) *Gateway

WithTLS 设置TLS配置

func (*Gateway) WithVersion

func (c *Gateway) WithVersion(version string) *Gateway

WithVersion 设置版本号

func (*Gateway) WithWSC

func (c *Gateway) WithWSC(cfg *wsc.WSC) *Gateway

WithWSC 设置 WebSocket 通信配置

type HTTP2

type HTTP2 struct {
	MaxConcurrentStreams  uint32 `mapstructure:"max-concurrent-streams" yaml:"max-concurrent-streams" json:"maxConcurrentStreams"`      // 单个连接最大并发流数
	MaxReadFrameSize      uint32 `mapstructure:"max-read-frame-size" yaml:"max-read-frame-size" json:"maxReadFrameSize"`                // 最大读取帧大小
	InitialWindowSize     int32  `mapstructure:"initial-window-size" yaml:"initial-window-size" json:"initialWindowSize"`               // 初始窗口大小
	InitialConnWindowSize int32  `mapstructure:"initial-conn-window-size" yaml:"initial-conn-window-size" json:"initialConnWindowSize"` // 初始连接窗口大小
}

HTTP2 HTTP/2配置

type HTTPServer

type HTTPServer struct {
	ModuleName           string            `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                                 // 模块名称
	Host                 string            `mapstructure:"host" yaml:"host" json:"host"`                                                     // 主机地址
	Port                 int               `mapstructure:"port" yaml:"port" json:"port"`                                                     // 端口
	Network              string            `mapstructure:"network" yaml:"network" json:"network"`                                            // 网络类型: tcp, tcp4, tcp6
	ReadTimeout          int               `mapstructure:"read-timeout" yaml:"read-timeout" json:"readTimeout"`                              // 读取超时(秒)
	ReadHeaderTimeout    int               `mapstructure:"read-header-timeout" yaml:"read-header-timeout" json:"readHeaderTimeout"`          // 读取请求头超时(秒),防止慢速攻击
	WriteTimeout         int               `mapstructure:"write-timeout" yaml:"write-timeout" json:"writeTimeout"`                           // 写入超时(秒)
	IdleTimeout          int               `mapstructure:"idle-timeout" yaml:"idle-timeout" json:"idleTimeout"`                              // 空闲超时(秒)
	MaxHeaderBytes       int               `mapstructure:"max-header-bytes" yaml:"max-header-bytes" json:"maxHeaderBytes"`                   // 最大请求头字节数
	EnableTls            bool              `mapstructure:"enable-tls" yaml:"enable-tls" json:"enableTls"`                                    // 是否启用TLS
	TLS                  *TLS              `mapstructure:"tls" yaml:"tls" json:"tls"`                                                        // TLS配置
	Headers              map[string]string `mapstructure:"headers" yaml:"headers" json:"headers"`                                            // 自定义头部
	Endpoint             string            `mapstructure:"-" yaml:"-" json:""`                                                               // 完整的服务端点地址(自动计算,不从配置文件读取)
	EnableGzipCompress   bool              `mapstructure:"enable-gzip-compress" yaml:"enable-gzip-compress" json:"enableGzipCompress"`       // 是否启用Gzip压缩
	GzipCompressionLevel int               `mapstructure:"gzip-compression-level" yaml:"gzip-compression-level" json:"gzipCompressionLevel"` // Gzip压缩级别 (1-9, 默认5)
	GzipMinSize          int               `mapstructure:"gzip-min-size" yaml:"gzip-min-size" json:"gzipMinSize"`                            // Gzip最小压缩大小(字节),小于此大小不压缩(默认1024)
	GzipSkipPaths        []string          `mapstructure:"gzip-skip-paths" yaml:"gzip-skip-paths" json:"gzipSkipPaths"`                      // Gzip跳过的路径前缀列表
	GzipSkipExtensions   []string          `mapstructure:"gzip-skip-extensions" yaml:"gzip-skip-extensions" json:"gzipSkipExtensions"`       // Gzip跳过的文件扩展名列表
	EnableHTTP2          bool              `mapstructure:"enable-http2" yaml:"enable-http2" json:"enableHttp2"`                              // 是否启用HTTP/2(h2c)
	HTTP2                *HTTP2            `mapstructure:"http2" yaml:"http2" json:"http2"`                                                  // HTTP/2配置
}

HTTPServer HTTP服务器配置

func DefaultHTTPServer

func DefaultHTTPServer() *HTTPServer

DefaultHTTPServer 创建默认HTTP服务器配置

func (*HTTPServer) AddHeader

func (h *HTTPServer) AddHeader(key, value string) *HTTPServer

AddHeader 添加自定义头部

func (*HTTPServer) AfterLoad

func (h *HTTPServer) AfterLoad() error

AfterLoad 配置加载后的钩子函数 - 用于计算衍生字段

func (*HTTPServer) BeforeLoad

func (h *HTTPServer) BeforeLoad() error

BeforeLoad 配置加载前的钩子函数

func (*HTTPServer) Clone

func (h *HTTPServer) Clone() internal.Configurable

Clone 返回配置的副本

func (*HTTPServer) DisableGzip

func (h *HTTPServer) DisableGzip() *HTTPServer

DisableGzip 禁用Gzip压缩

func (*HTTPServer) DisableHTTP2

func (h *HTTPServer) DisableHTTP2() *HTTPServer

DisableHTTP2 禁用HTTP/2

func (*HTTPServer) DisableTLS

func (h *HTTPServer) DisableTLS() *HTTPServer

DisableTLS 禁用TLS

func (*HTTPServer) EnableGzip

func (h *HTTPServer) EnableGzip() *HTTPServer

EnableGzip 启用Gzip压缩

func (*HTTPServer) EnableHTTP2Service

func (h *HTTPServer) EnableHTTP2Service() *HTTPServer

EnableHTTP2Service 启用HTTP/2

func (*HTTPServer) EnableTLSService

func (h *HTTPServer) EnableTLSService() *HTTPServer

EnableTLSService 启用TLS

func (*HTTPServer) Get

func (h *HTTPServer) Get() interface{}

Get 返回配置接口

func (*HTTPServer) GetEndpoint

func (h *HTTPServer) GetEndpoint() string

GetEndpoint 获取服务端点地址(如果未设置则自动计算)

func (*HTTPServer) Set

func (h *HTTPServer) Set(data interface{})

Set 设置配置数据

func (*HTTPServer) Validate

func (h *HTTPServer) Validate() error

Validate 验证配置

func (*HTTPServer) WithHTTP2Config

func (h *HTTPServer) WithHTTP2Config(maxStreams uint32, windowSize, connWindowSize int32) *HTTPServer

WithHTTP2Config 设置HTTP/2配置

func (*HTTPServer) WithHost

func (h *HTTPServer) WithHost(host string) *HTTPServer

WithHost 设置主机地址

func (*HTTPServer) WithPort

func (h *HTTPServer) WithPort(port int) *HTTPServer

WithPort 设置端口

func (*HTTPServer) WithTLS

func (h *HTTPServer) WithTLS(certFile, keyFile, caFile string) *HTTPServer

WithTLS 设置TLS配置

func (*HTTPServer) WithTimeouts

func (h *HTTPServer) WithTimeouts(read, write, idle int) *HTTPServer

WithTimeouts 设置超时配置

type JSON

type JSON struct {
	UseProtoNames   bool `mapstructure:"use-proto-names" yaml:"use-proto-names" json:"useProtoNames"`     // 使用proto字段名(snake_case),如 snake_case 而不是 snakeCase
	EmitUnpopulated bool `mapstructure:"emit-unpopulated" yaml:"emit-unpopulated" json:"emitUnpopulated"` // 输出所有字段,包括零值字段
	DiscardUnknown  bool `mapstructure:"discard-unknown" yaml:"discard-unknown" json:"discardUnknown"`    // 反序列化时忽略未知字段
}

JSON JSON序列化配置

func DefaultJSON

func DefaultJSON() *JSON

DefaultJSON 创建默认JSON配置

func (*JSON) AfterLoad

func (j *JSON) AfterLoad() error

AfterLoad 配置加载后的钩子函数

func (*JSON) BeforeLoad

func (j *JSON) BeforeLoad() error

BeforeLoad 配置加载前的钩子函数

func (*JSON) Clone

func (j *JSON) Clone() internal.Configurable

Clone 返回配置的副本

func (*JSON) Get

func (j *JSON) Get() interface{}

Get 返回配置接口

func (*JSON) Set

func (j *JSON) Set(data interface{})

Set 设置配置数据

func (*JSON) Validate

func (j *JSON) Validate() error

Validate 验证配置

func (*JSON) WithDiscardUnknown

func (j *JSON) WithDiscardUnknown(discard bool) *JSON

WithDiscardUnknown 设置是否忽略未知字段

func (*JSON) WithEmitUnpopulated

func (j *JSON) WithEmitUnpopulated(emit bool) *JSON

WithEmitUnpopulated 设置是否输出零值字段

func (*JSON) WithUseProtoNames

func (j *JSON) WithUseProtoNames(use bool) *JSON

WithUseProtoNames 设置是否使用proto字段名

type Listener

type Listener struct {
	Name     string `mapstructure:"name" yaml:"name" json:"name"`          // 监听器名称(如 "ops", "tenant")
	Host     string `mapstructure:"host" yaml:"host" json:"host"`          // 主机地址
	Port     int    `mapstructure:"port" yaml:"port" json:"port"`          // 端口
	Network  string `mapstructure:"network" yaml:"network" json:"network"` // 网络类型: tcp, tcp4, tcp6
	Endpoint string `mapstructure:"-" yaml:"-" json:""`                    // 完整端点地址(自动计算)
}

Listener 命名监听器配置,用于在同一进程中启动多个 HTTP 监听端口 典型场景:Ops 内网端口 + Tenant 公网端口

func DefaultListener

func DefaultListener(name string) *Listener

DefaultListener 创建默认监听器配置

func (*Listener) AfterLoad

func (l *Listener) AfterLoad() error

AfterLoad 配置加载后的钩子 - 计算衍生字段

func (*Listener) GetEndpoint

func (l *Listener) GetEndpoint() string

GetEndpoint 获取服务端点地址

func (*Listener) WithListenerHost

func (l *Listener) WithListenerHost(host string) *Listener

WithListenerHost 设置监听器主机地址

func (*Listener) WithListenerPort

func (l *Listener) WithListenerPort(port int) *Listener

WithListenerPort 设置监听器端口

type RequestContext

type RequestContext struct {
	// 标准请求头
	AuthorizationSources []common.AttributeSource `mapstructure:"authorization-sources" yaml:"authorization-sources" json:"authorizationSources"` // Authorization 提取来源
	AuthPayloadSources   []common.AttributeSource `mapstructure:"auth-payload-sources" yaml:"auth-payload-sources" json:"authPayloadSources"`     // Auth-Payload 提取来源
	JtiSources           []common.AttributeSource `mapstructure:"jti-sources" yaml:"jti-sources" json:"jtiSources"`                               // Jti 提取来源
	FamilyIdSources      []common.AttributeSource `mapstructure:"family-id-sources" yaml:"family-id-sources" json:"familyIdSources"`              // FamilyId 提取来源
	UserAgentSources     []common.AttributeSource `mapstructure:"user-agent-sources" yaml:"user-agent-sources" json:"userAgentSources"`           // User-Agent 提取来源
	AcceptSources        []common.AttributeSource `mapstructure:"accept-sources" yaml:"accept-sources" json:"acceptSources"`                      // Accept 提取来源
	CacheControlSources  []common.AttributeSource `mapstructure:"cache-control-sources" yaml:"cache-control-sources" json:"cacheControlSources"`  // Cache-Control 提取来源
	ConnectionSources    []common.AttributeSource `mapstructure:"connection-sources" yaml:"connection-sources" json:"connectionSources"`          // Connection 提取来源

	// 自定义请求头
	RequestIDSources      []common.AttributeSource `mapstructure:"request-id-sources" yaml:"request-id-sources" json:"requestIdSources"`                // X-Request-Id 提取来源
	TraceIDSources        []common.AttributeSource `mapstructure:"trace-id-sources" yaml:"trace-id-sources" json:"traceIdSources"`                      // X-Trace-Id 提取来源
	RealIPSources         []common.AttributeSource `mapstructure:"real-ip-sources" yaml:"real-ip-sources" json:"realIpSources"`                         // X-Real-IP 提取来源
	ForwardedForSources   []common.AttributeSource `mapstructure:"forwarded-for-sources" yaml:"forwarded-for-sources" json:"forwardedForSources"`       // X-Forwarded-For 提取来源
	ForwardedProtoSources []common.AttributeSource `mapstructure:"forwarded-proto-sources" yaml:"forwarded-proto-sources" json:"forwardedProtoSources"` // X-Forwarded-Proto 提取来源
	ForwardedHostSources  []common.AttributeSource `mapstructure:"forwarded-host-sources" yaml:"forwarded-host-sources" json:"forwardedHostSources"`    // X-Forwarded-Host 提取来源

	// 用户上下文相关头部
	ClientIDSources   []common.AttributeSource `mapstructure:"client-id-sources" yaml:"client-id-sources" json:"clientIdSources"`       // X-Client-ID 提取来源
	UserIDSources     []common.AttributeSource `mapstructure:"user-id-sources" yaml:"user-id-sources" json:"userIdSources"`             // X-User-ID 提取来源
	UserTypeSources   []common.AttributeSource `mapstructure:"user-type-sources" yaml:"user-type-sources" json:"userTypeSources"`       // X-User-Type 提取来源
	TenantIDSources   []common.AttributeSource `mapstructure:"tenant-id-sources" yaml:"tenant-id-sources" json:"tenantIdSources"`       // X-Tenant-ID 提取来源
	TenantCodeSources []common.AttributeSource `mapstructure:"tenant-code-sources" yaml:"tenant-code-sources" json:"tenantCodeSources"` // X-Tenant-Code 提取来源
	SessionIDSources  []common.AttributeSource `mapstructure:"session-id-sources" yaml:"session-id-sources" json:"sessionIdSources"`    // X-Session-ID 提取来源
	TimezoneSources   []common.AttributeSource `mapstructure:"timezone-sources" yaml:"timezone-sources" json:"timezoneSources"`         // X-Timezone 提取来源
	IDSources         []common.AttributeSource `mapstructure:"id-sources" yaml:"id-sources" json:"idSources"`                           // X-ID 提取来源
	DomainSources     []common.AttributeSource `mapstructure:"domain-sources" yaml:"domain-sources" json:"domainSources"`               // X-Domain 提取来源
	RoleCodeSources   []common.AttributeSource `mapstructure:"role-code-sources" yaml:"role-code-sources" json:"roleCodeSources"`       // X-Role-Code 提取来源
	PushTokenSources  []common.AttributeSource `mapstructure:"push-token-sources" yaml:"push-token-sources" json:"pushTokenSources"`    // X-Push-Token 提取来源
	TokenSources      []common.AttributeSource `mapstructure:"token-sources" yaml:"token-sources" json:"tokenSources"`                  // X-Token 提取来源

	// 设备和应用相关头部
	DeviceIDSources     []common.AttributeSource `mapstructure:"device-id-sources" yaml:"device-id-sources" json:"deviceIdSources"`             // X-Device-Id / X-Device-ID 提取来源
	AppIDSources        []common.AttributeSource `mapstructure:"app-id-sources" yaml:"app-id-sources" json:"appIdSources"`                      // X-App-Id 提取来源
	AppVersionSources   []common.AttributeSource `mapstructure:"app-version-sources" yaml:"app-version-sources" json:"appVersionSources"`       // X-App-Version 提取来源
	PlatformSources     []common.AttributeSource `mapstructure:"platform-sources" yaml:"platform-sources" json:"platformSources"`               // X-Platform 提取来源
	PlatformIDSources   []common.AttributeSource `mapstructure:"platform-id-sources" yaml:"platform-id-sources" json:"platformIDSources"`       // X-Platform-ID 提取来源
	PlatformCodeSources []common.AttributeSource `mapstructure:"platform-code-sources" yaml:"platform-code-sources" json:"platformCodeSources"` // X-Platform-Code 提取来源
	RegionIDSources     []common.AttributeSource `mapstructure:"region-id-sources" yaml:"region-id-sources" json:"regionIDSources"`             // X-Region-ID 提取来源
	RegionCodeSources   []common.AttributeSource `mapstructure:"region-code-sources" yaml:"region-code-sources" json:"regionCodeSources"`       // X-Region-Code 提取来源
	AgentLineIDSources  []common.AttributeSource `mapstructure:"agent-line-id-sources" yaml:"agent-line-id-sources" json:"agentLineIDSources"`  // X-Agent-Line 提取来源
	TimestampSources    []common.AttributeSource `mapstructure:"timestamp-sources" yaml:"timestamp-sources" json:"timestampSources"`            // X-Timestamp 提取来源
	SignatureSources    []common.AttributeSource `mapstructure:"signature-sources" yaml:"signature-sources" json:"signatureSources"`            // X-Signature 提取来源
	NonceSources        []common.AttributeSource `mapstructure:"nonce-sources" yaml:"nonce-sources" json:"nonceSources"`                        // X-Nonce 提取来源
	AccessKeySources    []common.AttributeSource `mapstructure:"access-key-sources" yaml:"access-key-sources" json:"accessKeySources"`          // X-Access-Key 提取来源

	// 其他请求头
	OriginSources    []common.AttributeSource `mapstructure:"origin-sources" yaml:"origin-sources" json:"originSources"`            // Origin 提取来源
	CSRFTokenSources []common.AttributeSource `mapstructure:"csrf-token-sources" yaml:"csrf-token-sources" json:"csrfTokenSources"` // X-CSRF-Token 提取来源
}

RequestContext Gateway 统一请求上下文提取配置 用于定义 RequestCommon 所需字段从哪些来源提取,供所有 middleware 共享

func DefaultRequestContext

func DefaultRequestContext() *RequestContext

DefaultRequestContext 创建默认请求上下文提取配置 DefaultRequestContext 的 header 来源 Key 一律写成 HTTP 规范形式(X-User-Id 而非 X-User-ID)

这不是风格偏好,是分配开销:Header.Get 内部会对 key 调 CanonicalMIMEHeaderKey, key 本来就是规范形式时直接返回、不分配;不是的话每次查找都要现算并分配一个新字符串 两种写法的查找结果完全一样(都归一到 X-User-Id),所以这是纯粹的削减

实测:提取器修好重复解析之后,canonicalMIMEHeaderKey 占了剩余分配的 100%, 把这些 key 写成规范形式后 header 路径降到零分配

新增 header 来源时请照规范形式写:连字符分段、每段仅首字母大写

[EN] Header source keys are written in canonical HTTP form (X-User-Id, not X-User-ID). This is not a style preference but an allocation: Header.Get canonicalizes the key on every lookup and returns it untouched only when it is already canonical. Both spellings resolve to the same header, so this is a pure saving -- after the repeated-parsing fix, canonicalMIMEHeaderKey accounted for all remaining allocations on the header path

func (*RequestContext) Clone

Clone 返回副本

func (*RequestContext) Get

func (c *RequestContext) Get() any

Get 返回配置接口

func (*RequestContext) GetSourceKeys

func (c *RequestContext) GetSourceKeys() *SourceKeys

GetSourceKeys 从当前 RequestContext 配置中提取所有字段的各来源首选 key 当配置变更时,调用此方法可获取最新的 key

func (*RequestContext) Set

func (c *RequestContext) Set(data any)

Set 设置配置

func (*RequestContext) Validate

func (c *RequestContext) Validate() error

Validate 验证配置

type SourceKeys

type SourceKeys struct {
	ID             FieldSourceKeys
	TraceID        FieldSourceKeys
	RequestID      FieldSourceKeys
	Authorization  FieldSourceKeys
	AuthPayload    FieldSourceKeys
	Jti            FieldSourceKeys
	FamilyId       FieldSourceKeys
	UserAgent      FieldSourceKeys
	ClientID       FieldSourceKeys
	UserID         FieldSourceKeys
	UserType       FieldSourceKeys
	Domain         FieldSourceKeys
	RoleCode       FieldSourceKeys
	TenantID       FieldSourceKeys
	TenantCode     FieldSourceKeys
	SessionID      FieldSourceKeys
	Timezone       FieldSourceKeys
	RealIP         FieldSourceKeys
	ForwardedFor   FieldSourceKeys
	ForwardedProto FieldSourceKeys
	ForwardedHost  FieldSourceKeys
	DeviceID       FieldSourceKeys
	AppID          FieldSourceKeys
	AppVersion     FieldSourceKeys
	PlatformID     FieldSourceKeys
	PlatformCode   FieldSourceKeys
	RegionID       FieldSourceKeys
	RegionCode     FieldSourceKeys
	AgentLineID    FieldSourceKeys
	Timestamp      FieldSourceKeys
	Signature      FieldSourceKeys
	Nonce          FieldSourceKeys
	AccessKey      FieldSourceKeys
	PushToken      FieldSourceKeys
	Token          FieldSourceKeys
	Origin         FieldSourceKeys
	CSRFToken      FieldSourceKeys
}

SourceKeys 存储每个字段对应的各来源类型的首选 Key 用于外部包动态获取 header / query / cookie key,而非依赖硬编码常量

type TLS

type TLS struct {
	CertFile            string         `mapstructure:"cert-file" yaml:"cert-file" json:"certFile"`                                    // 证书文件路径
	KeyFile             string         `mapstructure:"key-file" yaml:"key-file" json:"keyFile"`                                       // 私钥文件路径
	CAFile              string         `mapstructure:"ca-file" yaml:"ca-file" json:"caFile"`                                          // CA文件路径
	MinVersion          TLSVersion     `mapstructure:"min-version" yaml:"min-version" json:"minVersion"`                              // 最小TLS版本
	PreferServerCiphers bool           `mapstructure:"prefer-server-ciphers" yaml:"prefer-server-ciphers" json:"preferServerCiphers"` // 优先使用服务器密码套件
	NextProtos          []string       `mapstructure:"next-protos" yaml:"next-protos" json:"nextProtos"`                              // ALPN协议列表(如: h2, http/1.1)
	InsecureSkipVerify  bool           `mapstructure:"insecure-skip-verify" yaml:"insecure-skip-verify" json:"insecureSkipVerify"`    // 跳过证书验证(仅用于开发环境)
	ClientAuth          ClientAuthType `mapstructure:"client-auth" yaml:"client-auth" json:"clientAuth"`                              // 客户端认证模式
}

TLS TLS配置

type TLSVersion

type TLSVersion string

TLSVersion TLS 版本枚举

const (
	TLSVersion10 TLSVersion = "TLS10" // TLS 1.0
	TLSVersion11 TLSVersion = "TLS11" // TLS 1.1
	TLSVersion12 TLSVersion = "TLS12" // TLS 1.2
	TLSVersion13 TLSVersion = "TLS13" // TLS 1.3
)

func (TLSVersion) ToUint16

func (v TLSVersion) ToUint16() uint16

ToUint16 将 TLSVersion 转换为 tls.Config 使用的 uint16 值

Jump to

Keyboard shortcuts

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