Documentation
¶
Overview ¶
Package cfg 提供grpc-kit微服务脚手架的通用配置规范
Index ¶
- Constants
- Variables
- func NewHTTPTransport(config HTTPConfig) (*http.Transport, error)
- func NewTLSConfig(t *TLSConfig) (*tls.Config, error)
- type Authentication
- type Authorization
- type AutomationsConfig
- type BasicAuth
- type CacheboxConfig
- type CloudEventsConfig
- type ConnectionPool
- type DatabaseConfig
- type DebuggerConfig
- type DiscoverConfig
- type ExporterEnable
- type ExportersConfig
- type FlowClientConfig
- type FrontendConfig
- type FrontendInterface
- type GRPCService
- type HTTPConfig
- type HTTPService
- type KafkaSarama
- type KubernetesConfig
- type LRUCachebox
- type LocalConfig
- func (c *LocalConfig) AuthenticationTypeFrom(ctx context.Context) (string, bool)
- func (c *LocalConfig) Deregister() error
- func (c *LocalConfig) GetAdminDatabaseLion() (*lion.Client, error)
- func (c *LocalConfig) GetAppname() string
- func (c *LocalConfig) GetCacheboxRedisClient() (redis.UniversalClient, error)
- func (c *LocalConfig) GetClientDialOption(customOpts ...grpc.DialOption) []grpc.DialOption
- func (c *LocalConfig) GetClientStreamInterceptor() []grpc.StreamClientInterceptor
- func (c *LocalConfig) GetClientUnaryInterceptor() []grpc.UnaryClientInterceptor
- func (c *LocalConfig) GetCloudEvents() (eventclient.Client, error)
- func (c *LocalConfig) GetDatabase() (*sql.DB, error)
- func (c *LocalConfig) GetDatabaseEntSQLDriver() (*entsql.Driver, error)
- func (c *LocalConfig) GetFlowClientConfig() (*FlowClientConfig, error)
- func (c *LocalConfig) GetIndependent(t interface{}) error
- func (c *LocalConfig) GetIntegrationAdminServer() (*admin.KnownAdminAPI, error)
- func (c *LocalConfig) GetLRUCachebox() (LRUCachebox, error)
- func (c *LocalConfig) GetLogger() *logrus.Entry
- func (c *LocalConfig) GetNamespace() string
- func (c *LocalConfig) GetObjstoreBucket() (ObjstoreBucket, error)
- func (c *LocalConfig) GetObjstoreBucketReader() (ObjstoreBucketReader, error)
- func (c *LocalConfig) GetObjstoreMinioClient() (*minio.Client, error)
- func (c *LocalConfig) GetRBACData(ctx context.Context) *rbacv3.RBAC
- func (c *LocalConfig) GetRPCClient() (*rpc.Client, error)
- func (c *LocalConfig) GetRPCServer() (*rpc.Server, error)
- func (c *LocalConfig) GetServiceName() string
- func (c *LocalConfig) GetStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption
- func (c *LocalConfig) GetTraceID(ctx context.Context) string
- func (c *LocalConfig) GetUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption
- func (c *LocalConfig) GroupsFrom(ctx context.Context) ([]string, bool)
- func (c *LocalConfig) HTTPHandler(handler http.Handler) http.Handler
- func (c *LocalConfig) HTTPHandlerFrontend(mux *http.ServeMux, assets fs.FS) error
- func (c *LocalConfig) HTTPHandlerFunc(handler http.HandlerFunc) http.Handler
- func (c *LocalConfig) HasCacheboxEnabled() bool
- func (c *LocalConfig) IDTokenFrom(ctx context.Context) (auth.IDTokenClaims, bool)
- func (c *LocalConfig) Init() error
- func (c *LocalConfig) InitOpentracing() (interface{}, error)
- func (c *LocalConfig) InitPrometheus() error
- func (c *LocalConfig) Register(ctx context.Context, ...) (*http.ServeMux, error)
- func (c *LocalConfig) SecurityPolicyLoad(ctx context.Context, assets embed.FS) error
- func (c *LocalConfig) UsernameFrom(ctx context.Context) (string, bool)
- type MemoryCacheboxConfig
- type OIDCConfig
- type OIDCProvider
- type OPAEnvoyPlugin
- type OPAExternal
- type OPANative
- type OTLPGRPCConfig
- type OTLPHTTPConfig
- type ObjstoreAttributes
- type ObjstoreBucket
- type ObjstoreBucketReader
- type ObjstoreConfig
- type ObservablesConfig
- type ProxyBucket
- func (b *ProxyBucket) Attributes(ctx context.Context, objectKey string) (ObjstoreAttributes, error)
- func (b *ProxyBucket) Close() error
- func (b *ProxyBucket) CopyTo(ctx context.Context, srcObjectKey, dstObjectKey string) (ObjstoreAttributes, error)
- func (b *ProxyBucket) Delete(ctx context.Context, objectKey string) error
- func (b *ProxyBucket) Exists(ctx context.Context, objectKey string) (bool, error)
- func (b *ProxyBucket) Get(ctx context.Context, objectKey string) (io.ReadCloser, ObjstoreAttributes, error)
- func (b *ProxyBucket) GetRange(ctx context.Context, objectKey string, start, end int64) (io.ReadCloser, ObjstoreAttributes, error)
- func (b *ProxyBucket) IsObjNotFoundErr(err error) bool
- func (b *ProxyBucket) Iter(ctx context.Context, dir string, f func(string) error) error
- func (b *ProxyBucket) Name() string
- func (b *ProxyBucket) Upload(ctx context.Context, objectKey string, r io.Reader) (ObjstoreAttributes, error)
- type RedisCacheboxConfig
- type S3Bucket
- func (b *S3Bucket) Attributes(ctx context.Context, objectkey string) (ObjstoreAttributes, error)
- func (b *S3Bucket) Close() error
- func (b *S3Bucket) CopyTo(ctx context.Context, srcObjectKey, dstObjectKey string) (ObjstoreAttributes, error)
- func (b *S3Bucket) Delete(ctx context.Context, objectKey string) error
- func (b *S3Bucket) Exists(ctx context.Context, objectKey string) (bool, error)
- func (b *S3Bucket) Get(ctx context.Context, objectKey string) (io.ReadCloser, ObjstoreAttributes, error)
- func (b *S3Bucket) GetRange(ctx context.Context, objectKey string, start, end int64) (io.ReadCloser, ObjstoreAttributes, error)
- func (b *S3Bucket) IsObjNotFoundErr(err error) bool
- func (b *S3Bucket) Iter(ctx context.Context, dir string, f func(string) error) error
- func (b *S3Bucket) Name() string
- func (b *S3Bucket) Upload(ctx context.Context, objectKey string, r io.Reader) (ObjstoreAttributes, error)
- type S3Config
- type SSEConfig
- type SaramaConfig
- type SecurityConfig
- type ServicesConfig
- type TLSAutoConfig
- type TLSConfig
- type TelemetryConfig
- type TelemetryMetric
- type TelemetryTrace
- type URLStyle
- type WebInterfaceConfig
- type XDGSCRAMClient
Constants ¶
const ( // AuthenticationTypeBasic 用于http basic认证 AuthenticationTypeBasic = "basic" // AuthenticationTypeBearer 用于jwt认证 AuthenticationTypeBearer = "bearer" // AuthenticationTypeNone 用于指明rpc未使用任何认证 AuthenticationTypeNone = "none" // UsernameAnonymous 当未使用任何认证时的用户名 UsernameAnonymous = "anonymous" )
const ( // HTTPHeaderRequestID 全局请求ID HTTPHeaderRequestID = "X-REQUEST-ID" // HTTPHeaderHost 主机头 HTTPHeaderHost = "Host" // HTTPHeaderEtag 文件内容签名 HTTPHeaderEtag = "Etag" )
公共标准的 HTTP 请求头名称
const ( DatabaseDriverMysql = "mysql" DatabaseDriverPostgresql = "postgres" )
const ( URLStyleAuto = "auto" URLStylePath = "path" URLStyleVirtualHosted = "virtual-hosted" )
const ( ProxyContextHeader proxyContextKey = iota ProxyContextURLStyle )
const (
CloudEventsProtocolKafkaSarama = "kafka_sarama"
)
const (
// ScopeNameGRPCKit 用于该包产生链路、指标的权威名称
ScopeNameGRPCKit = "github.com/grpc-kit/pkg"
)
Variables ¶
var ( ErrDatabaseNotInit = errors.New("database not initialize") ErrDatabaseNotEnable = errors.New("database not enable") ErrDatabaseNotSupportDriver = errors.New("database driver not support") ErrDatabaseParamsMust = errors.New("database dbname username or password must") )
var SHA256 scram.HashGeneratorFcn = sha256.New
SHA256 hash generator function for SCRAM conversation
var SHA512 scram.HashGeneratorFcn = sha512.New
SHA512 hash generator function for SCRAM conversation
Functions ¶
func NewHTTPTransport ¶ added in v0.3.2
func NewHTTPTransport(config HTTPConfig) (*http.Transport, error)
NewHTTPTransport 创建默认的 http transport
Types ¶
type Authentication ¶
type Authentication struct {
InsecureRPCs []string `mapstructure:"insecure_rpcs"`
OIDCProvider *OIDCProvider `mapstructure:"oidc_provider"`
HTTPUsers []*BasicAuth `mapstructure:"http_users"`
}
Authentication 用于认证
type Authorization ¶
type Authorization struct {
AllowedGroups []string `mapstructure:"allowed_groups"`
OPANative OPANative `mapstructure:"opa_native"`
OPAExternal OPAExternal `mapstructure:"opa_external"`
OPAEnvoyPlugin OPAEnvoyPlugin `mapstructure:"opa_envoy_plugin"`
}
Authorization 用于鉴权
type AutomationsConfig ¶ added in v0.3.8
type AutomationsConfig struct {
// 全局是否启用
Enable bool `mapstructure:"enable"`
// 连接 k8s 集群
Kubernetes KubernetesConfig `mapstructure:"kubernetes"`
// contains filtered or unexported fields
}
AutomationsConfig 流程编排配置
type BasicAuth ¶
type BasicAuth struct {
UserID int64 `mapstructure:"user_id"`
Username string `mapstructure:"username"`
// Deprecated: 使用 PasswordHash 代替,优先级低于 Password 配置
Password string `mapstructure:"password"`
PasswordHash string `mapstructure:"password_hash"`
Groups []string `mapstructure:"groups"`
// 租户,默认均为 'default' 下
Tenant string `mapstructure:"tenant"`
}
BasicAuth 用于HTTP基本认证的用户权限定义
type CacheboxConfig ¶ added in v0.3.8
type CacheboxConfig struct {
// 全局是否启用
Enable bool `mapstructure:"enable"`
// 使用的驱动类型
Driver string `mapstructure:"driver"`
// MemoryCacheboxConfig 内存缓存配置
Memory MemoryCacheboxConfig `mapstructure:"memory"`
// RedisCacheboxConfig redis 缓存配置
Redis RedisCacheboxConfig `mapstructure:"redis"`
// contains filtered or unexported fields
}
CacheboxConfig 缓存配置,区别于数据库配置,缓存的数据可以丢失
type CloudEventsConfig ¶
type CloudEventsConfig struct {
Enable bool `mapstructure:"enable"`
Protocol string `mapstructure:"protocol"`
KafkaSarama KafkaSarama `mapstructure:"kafka_sarama"`
// 审计功能配置
AuditPolicy struct {
// 是否启用审计功能,默认为 false
Enabled bool `mapstructure:"enabled"`
Topic string `mapstructure:"topic"`
Level string `mapstructure:"level"`
Event struct {
// 在 request 阶段审计日志必须推送成功,否则本次请求失败,默认为 true
MustSucceed *bool `mapstructure:"must_succeed"`
} `mapstructure:"event"`
} `mapstructure:"audit_policy"`
// contains filtered or unexported fields
}
CloudEventsConfig cloudevents事件配置
type ConnectionPool ¶
type ConnectionPool struct {
MaxIdleTime time.Duration `mapstructure:"max_idle_time"`
MaxLifeTime time.Duration `mapstructure:"max_life_time"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
MaxOpenConns int `mapstructure:"max_open_conns"`
}
ConnectionPool 数据库连接池配置
type DatabaseConfig ¶
type DatabaseConfig struct {
Enable bool `mapstructure:"enable"`
Driver string `mapstructure:"driver"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Protocol string `mapstructure:"protocol"`
Address string `mapstructure:"address"`
DBName string `mapstructure:"dbname"`
Parameters string `mapstructure:"parameters"`
ConnectionPool ConnectionPool `mapstructure:"connection_pool"`
// contains filtered or unexported fields
}
DatabaseConfig 数据库设置,指关系数据库,数据不允许丢失,如postgres、mysql
type DebuggerConfig ¶
type DebuggerConfig struct {
EnablePprof bool `mapstructure:"enable_pprof"`
LogLevel string `mapstructure:"log_level"`
LogFormat string `mapstructure:"log_format"`
}
DebuggerConfig 日志配置,用于设定服务启动后日志输出级别格式等
type DiscoverConfig ¶
type DiscoverConfig struct {
Driver string `mapstructure:"driver"`
Endpoints []string `mapstructure:"endpoints"`
TLS *TLSConfig `mapstructure:"tls" json:",omitempty"`
Heartbeat int64 `mapstructure:"heartbeat"`
}
DiscoverConfig 服务注册,服务启动后如何汇报自身
type ExporterEnable ¶ added in v0.3.3
type ExporterEnable struct {
OTLP *bool `mapstructure:"otlp"`
OTLPHTTP *bool `mapstructure:"otlphttp"`
Logging *bool `mapstructure:"logging"`
Prometheus *bool `mapstructure:"prometheus"`
}
ExporterEnable 配置是否启用特定 exporter
type ExportersConfig ¶ added in v0.3.3
type ExportersConfig struct {
OTLPGRPC *OTLPGRPCConfig `mapstructure:"otlp"`
OTLPHTTP *OTLPHTTPConfig `mapstructure:"otlphttp"`
Prometheus *struct {
MetricsURLPath string `mapstructure:"metrics_url_path"`
}
Logging *struct {
PrettyPrint bool `mapstructure:"pretty_print"`
MetricsFilePath string `mapstructure:"metrics_file_path"`
TracesFilePath string `mapstructure:"traces_file_path"`
} `mapstructure:"logging"`
}
ExportersConfig 可观测遥感数据导出目标地址
type FlowClientConfig ¶ added in v0.3.8
FlowClientConfig 流程编排客户端配置
func (*FlowClientConfig) GetScriptSource ¶ added in v0.3.8
GetScriptSource 用于获取脚本内容,从 db 或本地中
type FrontendConfig ¶ added in v0.3.5
type FrontendConfig struct {
Enable *bool `mapstructure:"enable"`
Interface FrontendInterface `mapstructure:"interface"`
}
FrontendConfig 用于表示前端配置
type FrontendInterface ¶ added in v0.3.5
type FrontendInterface struct {
Admin *WebInterfaceConfig `mapstructure:"admin"` // 用户管理后台配置
Openapi *WebInterfaceConfig `mapstructure:"openapi"` // 后端 API 接口文档
Webroot *WebInterfaceConfig `mapstructure:"webroot"` // 站点根路径配置
}
FrontendInterface 表示前端界面配置
type GRPCService ¶ added in v0.3.5
type GRPCService struct {
Enabled *bool `mapstructure:"enabled"`
Address string `mapstructure:"address"`
TLSServer *TLSConfig `mapstructure:"tls_server"`
}
GRPCService 用于 gRPC 服务配置
type HTTPConfig ¶ added in v0.3.2
type HTTPConfig struct {
// 允许你自定义 TLS 配置,以满足特定的需求,例如指定根证书、跳过证书验证、设置密码套件等
TLSClientConfig TLSConfig `mapstructure:"tls_client_config" yaml:"tls_client_config"`
// 可以控制在建立 TLS 握手过程中等待的最大时间,客户端和服务器之间进行密钥交换和协商加密参数等操作
// 如果在指定的超时时间内未完成握手,客户端可以终止连接或采取其他处理方式
TLSHandshakeTimeout time.Duration `mapstructure:"tls_handshake_timeout" yaml:"tls_handshake_timeout"`
// HTTP 的 keep-alive 是一种机制,允许客户端在单个 TCP 连接上发送多个 HTTP 请求,而无需为每个请求都建立和关闭连接
// 是否禁用 HTTP 的 keep-alive 功能,这样每个 HTTP 请求都会使用一个新的连接,意味着每次请求都需要建立和关闭连接
DisableKeepAlives bool `mapstructure:"disable_keep_alives" yaml:"disable_keep_alives"`
// 如果开启则请求中不会包含 "Accept-Encoding: gzip" 的请求头,即禁止了请求压缩,这意味着即使服务端返回的响应使用了gzip压缩,Transport也不会自动解压缩响应体
DisableCompression bool `mapstructure:"disable_compression" yaml:"disable_compression"`
// 可以控制在空闲连接池中保持的最大连接数,超过这个数量的空闲连接将被关闭
// 通过使用 keep-alive 机制,客户端可以在多次请求之间重用已经建立的连接,以减少每次请求的连接建立和断开的开销
MaxIdleConns int `mapstructure:"max_idle_conns" yaml:"max_idle_conns"`
// 可以针对每个主机控制保持的最大空闲连接数,这可以使每个主机具有独立的连接池,而不是使用全局的连接池
// 每个主机可以独立地管理和复用空闲连接,以优化连接的使用和性能
MaxIdleConnsPerHost int `mapstructure:"max_idle_conns_per_host" yaml:"max_idle_conns_per_host"`
// 用于可选地限制每个主机的总连接数,包括处于拨号、活动和空闲状态的连接
MaxConnsPerHost int `mapstructure:"max_conns_per_host" yaml:"max_conns_per_host"`
// 空闲连接的超时时间,指定空闲连接在关闭之前保持的最长时间
IdleConnTimeout time.Duration `mapstructure:"idle_conn_timeout" yaml:"idle_conn_timeout"`
// 客户端在发送请求后等待服务器响应头的时间,如果在指定的超时时间内未收到响应头,客户端可以终止连接或采取其他处理方式
ResponseHeaderTimeout time.Duration `mapstructure:"response_header_timeout" yaml:"response_header_timeout"`
// 用于在完全发送请求头后,等待服务器首次响应头的时间
ExpectContinueTimeout time.Duration `mapstructure:"expect_continue_timeout" yaml:"expect_continue_timeout"`
// 可以控制接收和处理服务器响应头的大小
// 响应头中包含了诸如状态码、响应头字段等信息,如果服务器的响应头超过了指定的最大字节数,那么将会触发一个错误,导致请求失败
MaxResponseHeaderBytes int64 `mapstructure:"max_response_header_bytes" yaml:"max_response_header_bytes"`
// 用于控制写缓冲区大小,它是用于临时存储要发送到传输层的数据的内存区域
// 通过使用写缓冲区可以减少实际的写操作次数,提高写入数据的效率,较大的写缓冲区可以在一次写操作中发送更多的数据,减少了频繁的系统调用和网络开销
// 设置为 0,则会使用默认值(目前为4KB)
WriteBufferSize int `mapstructure:"write_buffer_size" yaml:"write_buffer_size"`
// 用于控制读缓冲区大小,它是用于临时存储从传输层读取的数据的内存区域
// 通过使用读缓冲区可以减少实际的读操作次数,提高从传输层读取数据的效率,较大的读缓冲区可以一次性读取更多的数据,减少了频繁的系统调用和网络开销
// 设置为 0,则会使用默认值(目前为4KB)
ReadBufferSize int `mapstructure:"read_buffer_size" yaml:"read_buffer_size"`
// 在配置了 Dial、DialTLS、DialContext 函数或 TLSClientConfig 时,会禁用 HTTP/2
// 这时可以配置开启,也会尝试使用 HTTP/2 协议进行升级,不过仍然需要确保服务器支持 HTTP/2 协议才能成功升级
ForceAttemptHTTP2 bool `mapstructure:"force_attempt_http2" yaml:"force_attempt_http2"`
}
HTTPConfig 用于控制客户端通过 http 协议连接服务端的一些能力
type HTTPService ¶ added in v0.3.5
type HTTPService struct {
Enabled *bool `mapstructure:"enabled"`
Address string `mapstructure:"address"`
TLSAuto *TLSAutoConfig `mapstructure:"tls_auto"`
TLSServer *TLSConfig `mapstructure:"tls_server"`
TLSClient *TLSConfig `mapstructure:"tls_client"`
}
HTTPService 用于 HTTP 服务配置
type KafkaSarama ¶
type KafkaSarama struct {
Brokers []string `mapstructure:"brokers"`
Topic string `mapstructure:"topic"`
Config SaramaConfig `mapstructure:"config"`
}
KafkaSarama xx
type KubernetesConfig ¶ added in v0.3.8
type KubernetesConfig struct {
// 配置文件路径,既 kubeconfig 文件路径
ConfigPath string `mapstructure:"config_path"`
// 结构同 https://pkg.go.dev/k8s.io/client-go@v0.31.2/rest#Config
RestConfig *struct {
Host string `mapstructure:"host"`
BearerToken string `mapstructure:"bearer_token"`
BearerTokenFile string `mapstructure:"bearer_token_file"`
TLSClientConfig struct {
Insecure bool `mapstructure:"insecure"`
} `mapstructure:"tls_client_config"`
} `mapstructure:"rest_config"`
}
KubernetesConfig 连接 k8s 集群
type LRUCachebox ¶ added in v0.3.8
type LRUCachebox interface {
// Remove 重内存缓存移除值
Remove(ctx context.Context, key string) bool
// SetValue 向内存缓存添加值
SetValue(ctx context.Context, key string, value any) bool
// GetStructValue 从内存缓存获取值,并填充用户给定的类型
GetStructValue(ctx context.Context, key string, ptx any) bool
}
LRUCachebox 缓存实现 LRU 效果
type LocalConfig ¶
type LocalConfig struct {
Services *ServicesConfig `json:",omitempty"` // 基础服务配置
Discover *DiscoverConfig `json:",omitempty"` // 服务注册配置
Security *SecurityConfig `json:",omitempty"` // 认证鉴权配置
Database *DatabaseConfig `json:",omitempty"` // 关系数据配置
Cachebox *CacheboxConfig `json:",omitempty"` // 缓存服务配置
Debugger *DebuggerConfig `json:",omitempty"` // 日志调试配置
Objstore *ObjstoreConfig `json:",omitempty"` // 对象存储配置
Frontend *FrontendConfig `json:",omitempty"` // 前端服务配置
Observables *ObservablesConfig `json:",omitempty"` // 可观测性配置
CloudEvents *CloudEventsConfig `json:",omitempty"` // 公共事件配置
Automations *AutomationsConfig `json:",omitempty"` // 流程编排配置
Independent interface{} `json:",omitempty"` // 应用私有配置
// contains filtered or unexported fields
}
LocalConfig 本地配置,全局微服务配置结构
func (*LocalConfig) AuthenticationTypeFrom ¶
func (c *LocalConfig) AuthenticationTypeFrom(ctx context.Context) (string, bool)
AuthenticationTypeFrom 用于获取当前会话的认证方式
func (*LocalConfig) GetAdminDatabaseLion ¶
func (c *LocalConfig) GetAdminDatabaseLion() (*lion.Client, error)
GetAdminDatabaseLion 用于测试 Lion 配置 TODO: 这里用于测试 lion 数据库
func (*LocalConfig) GetAppname ¶ added in v0.3.8
func (c *LocalConfig) GetAppname() string
GetAppname 用于获取应用名称
func (*LocalConfig) GetCacheboxRedisClient ¶ added in v0.3.8
func (c *LocalConfig) GetCacheboxRedisClient() (redis.UniversalClient, error)
GetCacheboxRedisClient 用于获取缓存服务中初始化的 redis 连接
func (*LocalConfig) GetClientDialOption ¶
func (c *LocalConfig) GetClientDialOption(customOpts ...grpc.DialOption) []grpc.DialOption
GetClientDialOption 获取客户端连接的设置
func (*LocalConfig) GetClientStreamInterceptor ¶
func (c *LocalConfig) GetClientStreamInterceptor() []grpc.StreamClientInterceptor
GetClientStreamInterceptor 获取客户端默认流拦截器
func (*LocalConfig) GetClientUnaryInterceptor ¶
func (c *LocalConfig) GetClientUnaryInterceptor() []grpc.UnaryClientInterceptor
GetClientUnaryInterceptor 获取客户端默认一元拦截器
func (*LocalConfig) GetCloudEvents ¶
func (c *LocalConfig) GetCloudEvents() (eventclient.Client, error)
GetCloudEvents 用于获取 cloudevents 连接客户端
func (*LocalConfig) GetDatabase ¶
func (c *LocalConfig) GetDatabase() (*sql.DB, error)
GetDatabase 获取数据库实例
func (*LocalConfig) GetDatabaseEntSQLDriver ¶ added in v0.3.7
func (c *LocalConfig) GetDatabaseEntSQLDriver() (*entsql.Driver, error)
GetDatabaseEntSQLDriver 获取以 ent 框架的数据库模型实例
func (*LocalConfig) GetFlowClientConfig ¶ added in v0.3.8
func (c *LocalConfig) GetFlowClientConfig() (*FlowClientConfig, error)
GetFlowClientConfig 用于获取 flow client 配置
func (*LocalConfig) GetIndependent ¶
func (c *LocalConfig) GetIndependent(t interface{}) error
GetIndependent 用于获取各个微服务独立的配置
func (*LocalConfig) GetIntegrationAdminServer ¶
func (c *LocalConfig) GetIntegrationAdminServer() (*admin.KnownAdminAPI, error)
GetIntegrationAdminServer 用于获取集成管理服务
func (*LocalConfig) GetLRUCachebox ¶ added in v0.3.8
func (c *LocalConfig) GetLRUCachebox() (LRUCachebox, error)
GetLRUCachebox 用于获取 LRU 缓存
func (*LocalConfig) GetNamespace ¶ added in v0.3.8
func (c *LocalConfig) GetNamespace() string
GetNamespace 用于获取应用的命名空间
func (*LocalConfig) GetObjstoreBucket ¶ added in v0.3.2
func (c *LocalConfig) GetObjstoreBucket() (ObjstoreBucket, error)
GetObjstoreBucket 用于获取对象存储
func (*LocalConfig) GetObjstoreBucketReader ¶ added in v0.3.2
func (c *LocalConfig) GetObjstoreBucketReader() (ObjstoreBucketReader, error)
GetObjstoreBucketReader 用于获取对象存储
func (*LocalConfig) GetObjstoreMinioClient ¶ added in v0.3.2
func (c *LocalConfig) GetObjstoreMinioClient() (*minio.Client, error)
GetObjstoreMinioClient 获取内部 minio 客户端连接
func (*LocalConfig) GetRBACData ¶ added in v0.3.8
func (c *LocalConfig) GetRBACData(ctx context.Context) *rbacv3.RBAC
GetRBACData 用于获取 RBAC 数据
func (*LocalConfig) GetRPCClient ¶
func (c *LocalConfig) GetRPCClient() (*rpc.Client, error)
GetRPCClient 获取rpc客户端实例,TODO;(未完善,当前主要解耦框架模版)
func (*LocalConfig) GetRPCServer ¶
func (c *LocalConfig) GetRPCServer() (*rpc.Server, error)
GetRPCServer 获取rpc服务端实例,TODO;(未完善,当前主要解耦框架模版)
func (*LocalConfig) GetServiceName ¶
func (c *LocalConfig) GetServiceName() string
GetServiceName 用于获取微服务名称
func (*LocalConfig) GetStreamInterceptor ¶
func (c *LocalConfig) GetStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption
GetStreamInterceptor xx
func (*LocalConfig) GetTraceID ¶ added in v0.3.3
func (c *LocalConfig) GetTraceID(ctx context.Context) string
GetTraceID 用于获取 opentelemetry 下的 trace id
func (*LocalConfig) GetUnaryInterceptor ¶
func (c *LocalConfig) GetUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption
GetUnaryInterceptor 用于获取gRPC的一元拦截器
func (*LocalConfig) GroupsFrom ¶
func (c *LocalConfig) GroupsFrom(ctx context.Context) ([]string, bool)
GroupsFrom 用于获取当前会话的用户组列表
func (*LocalConfig) HTTPHandler ¶ added in v0.3.3
func (c *LocalConfig) HTTPHandler(handler http.Handler) http.Handler
HTTPHandler 用于植入 otelhttp 链路跟踪与鉴权中间件
func (*LocalConfig) HTTPHandlerFrontend ¶ added in v0.3.5
HTTPHandlerFrontend 用于处理前端相关服务
func (*LocalConfig) HTTPHandlerFunc ¶ added in v0.3.3
func (c *LocalConfig) HTTPHandlerFunc(handler http.HandlerFunc) http.Handler
HTTPHandlerFunc 功能同 HTTPHandler
func (*LocalConfig) HasCacheboxEnabled ¶ added in v0.3.8
func (c *LocalConfig) HasCacheboxEnabled() bool
HasCacheboxEnabled 用于判断是否启用缓存
func (*LocalConfig) IDTokenFrom ¶
func (c *LocalConfig) IDTokenFrom(ctx context.Context) (auth.IDTokenClaims, bool)
IDTokenFrom 用于获取当前会话的IDToken
func (*LocalConfig) InitOpentracing ¶
func (c *LocalConfig) InitOpentracing() (interface{}, error)
InitOpentracing 初始化全局分布式链路追踪
func (*LocalConfig) InitPrometheus ¶ added in v0.3.3
func (c *LocalConfig) InitPrometheus() error
InitPrometheus 用于初始化可观测性
func (*LocalConfig) Register ¶
func (c *LocalConfig) Register(ctx context.Context, gw func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) (err error), opts ...runtime.ServeMuxOption) (*http.ServeMux, error)
Register 用于登记服务信息至注册中心
func (*LocalConfig) SecurityPolicyLoad ¶ added in v0.3.6
SecurityPolicyLoad 加载服务本地安全策略
func (*LocalConfig) UsernameFrom ¶
func (c *LocalConfig) UsernameFrom(ctx context.Context) (string, bool)
UsernameFrom 用于获取当前会话的用户名
type MemoryCacheboxConfig ¶ added in v0.3.8
type MemoryCacheboxConfig struct {
// 最大缓存条数,超过了会进行驱逐,默认无限制
MaxEntry int `mapstructure:"max_entry"`
}
MemoryCacheboxConfig 内存缓存配置
type OIDCConfig ¶
type OIDCConfig struct {
ClientID string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
SupportedSigningAlgs []string `mapstructure:"supported_signing_algs"`
SkipClientIDCheck bool `mapstructure:"skip_client_id_check"`
SkipExpiryCheck bool `mapstructure:"skip_expiry_check"`
SkipIssuerCheck bool `mapstructure:"skip_issuer_check"`
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
}
OIDCConfig 用于OIDC验证相关配置
type OIDCProvider ¶
type OIDCProvider struct {
Issuer string `mapstructure:"issuer"`
Config *OIDCConfig `mapstructure:"config"`
}
OIDCProvider 用于OIDC认证提供方配置
type OPAEnvoyPlugin ¶ added in v0.3.6
type OPAEnvoyPlugin struct {
Enabled *bool `mapstructure:"enabled"`
Service struct {
GRPCAddress string `mapstructure:"grpc_address"`
} `mapstructure:"service"`
}
OPAEnvoyPlugin 使用 envoy 的 opa 插件服务
type OPAExternal ¶ added in v0.3.6
type OPAExternal struct {
Enabled *bool `mapstructure:"enabled"`
Config string `mapstructure:"config"`
}
OPAExternal 外部的 opa 服务
type OPANative ¶ added in v0.3.6
type OPANative struct {
Enabled *bool `mapstructure:"enabled"`
Policy struct {
AuthFile string `mapstructure:"auth_file"`
DataFile string `mapstructure:"data_file"`
} `mapstructure:"policy"`
}
OPANative 内嵌的 opa 组件
type OTLPGRPCConfig ¶ added in v0.3.3
type OTLPGRPCConfig struct {
// 上报数据至服务端地址,如:http://localhost:4317
Endpoint string `mapstructure:"endpoint"`
Headers map[string]string `mapstructure:"headers"`
}
OTLPGRPCConfig 使用 otlp grpc 协议上报数据
type OTLPHTTPConfig ¶ added in v0.3.3
type OTLPHTTPConfig struct {
// 上报数据至服务端地址,如:http://localhost:4318
Endpoint string `mapstructure:"endpoint"`
Headers map[string]string `mapstructure:"headers"`
// 保持格式同
// https://github.com/open-telemetry/opentelemetry-collector/blob/main/receiver/otlpreceiver/config.go
TracesURLPath string `mapstructure:"traces_url_path,omitempty"`
MetricsURLPath string `mapstructure:"metrics_url_path,omitempty"`
LogsURLPath string `mapstructure:"logs_url_path,omitempty"`
}
OTLPHTTPConfig 使用 otlp http 协议上报数据
type ObjstoreAttributes ¶ added in v0.3.2
type ObjstoreAttributes struct {
// ETag 对象文件内容的 md5 值
ETag string `json:"etag"`
// LastModified 对象文件最近被修改时间
LastModified time.Time `json:"last_modified"`
// Size 对象文件大小,单位 bytes
Size int64 `json:"size"`
// UserMetadata 用户额外定义该对象的元数据,以 "x-amz-meta-*" 请求头返回
UserMetadata map[string]string `json:"user_metadata"`
// UserTags 用户定义对象文件关联的标签
UserTags map[string]string `json:"user_tags"`
// VersionID 用于说明本次文件版本号
VersionID string `json:"version_id"`
}
ObjstoreAttributes 对象属性信息,如:last_modified、etag 等
type ObjstoreBucket ¶ added in v0.3.2
type ObjstoreBucket interface {
io.Closer
ObjstoreBucketReader
// Name 获取默认的 bucket 名称
Name() string
// Upload 用于上传对象到默认的 bucket 里
Upload(ctx context.Context, objectKey string, r io.Reader) (ObjstoreAttributes, error)
// Delete 用于删除对象在默认的 bucket 里
Delete(ctx context.Context, objectKey string) error
// CopyTo 用于拷贝对象在默认 bucket 里
CopyTo(ctx context.Context, srcObjectKey, dstObjectKey string) (ObjstoreAttributes, error)
}
ObjstoreBucket 抽象化包装,以简化使用,读写操作权限
type ObjstoreBucketReader ¶ added in v0.3.2
type ObjstoreBucketReader interface {
// Get 用于获取默认 bucket 的对象内容
Get(ctx context.Context, objectKey string) (io.ReadCloser, ObjstoreAttributes, error)
// Iter 用于遍历默认 bucket 里的对象文件
Iter(ctx context.Context, dir string, f func(string) error) error
// GetRange 用于获取默认 bucket 中对象指定位置的内容
GetRange(ctx context.Context, objectKey string, start, end int64) (io.ReadCloser, ObjstoreAttributes, error)
// Exists 用于判断默认 bucket 是否存在该对象
Exists(ctx context.Context, objectKey string) (bool, error)
// Attributes 用于获取默认 bucket 中对象的额外属性
Attributes(ctx context.Context, objectKey string) (ObjstoreAttributes, error)
// IsObjNotFoundErr 错误是否为查询的对象不存在
IsObjNotFoundErr(err error) bool
}
ObjstoreBucketReader 抽象化包装,以简化使用,只读操作权限
type ObjstoreConfig ¶ added in v0.3.2
type ObjstoreConfig struct {
Enable bool `mapstructure:"enable"`
Type string `mapstructure:"type"`
Config S3Config `mapstructure:"config"`
// contains filtered or unexported fields
}
ObjstoreConfig 对象存储相关配置
func (*ObjstoreConfig) BucketClient ¶ added in v0.3.2
func (o *ObjstoreConfig) BucketClient(logger *logrus.Entry) (ObjstoreBucket, error)
BucketClient 获取对象存储客户端实例
type ObservablesConfig ¶ added in v0.3.3
type ObservablesConfig struct {
// 全局是否启动可观测性,默认启用
Enable *bool `mapstructure:"enable"`
// 首次初始化后配置默认值
Telemetry *TelemetryConfig `mapstructure:"telemetry"`
// 可观测性数据上报服务地址
Exporters *ExportersConfig `mapstructure:"exporters"`
// contains filtered or unexported fields
}
ObservablesConfig 用于客观性配置
type ProxyBucket ¶ added in v0.3.2
type ProxyBucket struct {
// contains filtered or unexported fields
}
ProxyBucket xx
func (*ProxyBucket) Attributes ¶ added in v0.3.2
func (b *ProxyBucket) Attributes(ctx context.Context, objectKey string) (ObjstoreAttributes, error)
Attributes 用于获取默认 bucket 中对象的额外属性
func (*ProxyBucket) CopyTo ¶ added in v0.3.2
func (b *ProxyBucket) CopyTo(ctx context.Context, srcObjectKey, dstObjectKey string) (ObjstoreAttributes, error)
CopyTo 用于拷贝对象在默认 bucket 里
func (*ProxyBucket) Delete ¶ added in v0.3.2
func (b *ProxyBucket) Delete(ctx context.Context, objectKey string) error
Delete 用于删除对象在默认的 bucket 里
func (*ProxyBucket) Get ¶ added in v0.3.2
func (b *ProxyBucket) Get(ctx context.Context, objectKey string) (io.ReadCloser, ObjstoreAttributes, error)
Get 用于获取默认 bucket 的对象内容
func (*ProxyBucket) GetRange ¶ added in v0.3.2
func (b *ProxyBucket) GetRange(ctx context.Context, objectKey string, start, end int64) (io.ReadCloser, ObjstoreAttributes, error)
GetRange 用于获取默认 bucket 中对象指定位置的内容
func (*ProxyBucket) IsObjNotFoundErr ¶ added in v0.3.2
func (b *ProxyBucket) IsObjNotFoundErr(err error) bool
IsObjNotFoundErr 错误是否为查询的对象不存在
func (*ProxyBucket) Upload ¶ added in v0.3.2
func (b *ProxyBucket) Upload(ctx context.Context, objectKey string, r io.Reader) (ObjstoreAttributes, error)
Upload 用于上传对象到默认的 bucket 里
type RedisCacheboxConfig ¶ added in v0.3.8
type RedisCacheboxConfig struct {
Endpoints []string `mapstructure:"endpoints"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
DBNumber int `mapstructure:"db_number"`
Sentinel struct {
MasterName string `mapstructure:"master_name"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
} `mapstructure:"sentinel"`
TLSClientConfig *TLSConfig `mapstructure:"tls_client_config"`
}
RedisCacheboxConfig redis 缓存配置
type S3Bucket ¶ added in v0.3.2
type S3Bucket struct {
// contains filtered or unexported fields
}
S3Bucket 用于实现 ObjstoreBucket 简化对象存储接口的使用
func (*S3Bucket) Attributes ¶ added in v0.3.2
Attributes 用于获取默认 bucket 中对象的额外属性
func (*S3Bucket) CopyTo ¶ added in v0.3.2
func (b *S3Bucket) CopyTo(ctx context.Context, srcObjectKey, dstObjectKey string) (ObjstoreAttributes, error)
CopyTo 用于拷贝同 bucket 下的对象文件,对象名不以 '/' 开头
func (*S3Bucket) Get ¶ added in v0.3.2
func (b *S3Bucket) Get(ctx context.Context, objectKey string) (io.ReadCloser, ObjstoreAttributes, error)
Get 用于获取默认 bucket 的对象内容
func (*S3Bucket) GetRange ¶ added in v0.3.2
func (b *S3Bucket) GetRange(ctx context.Context, objectKey string, start, end int64) (io.ReadCloser, ObjstoreAttributes, error)
GetRange 用于获取默认 bucket 中对象指定位置的内容
func (*S3Bucket) IsObjNotFoundErr ¶ added in v0.3.2
IsObjNotFoundErr 判断释放为对象不存在
type S3Config ¶ added in v0.3.2
type S3Config struct {
Bucket string `mapstructure:"bucket" yaml:"bucket"`
Endpoint string `mapstructure:"endpoint" yaml:"endpoint"`
Region string `mapstructure:"region" yaml:"region"`
AccessKey string `mapstructure:"access_key" yaml:"access_key"`
Insecure bool `mapstructure:"insecure" yaml:"insecure"`
SecretKey string `mapstructure:"secret_key" yaml:"secret_key"`
SessionToken string `mapstructure:"session_token" yaml:"session_token"`
PutUserMetadata map[string]string `mapstructure:"put_user_metadata" yaml:"put_user_metadata"`
PutUserTags map[string]string `mapstructure:"put_user_tags" yaml:"put_user_tags"`
HTTPConfig HTTPConfig `mapstructure:"http_config" yaml:"http_config"`
SignatureVersion string `mapstructure:"signature_version" yaml:"signature_version"`
ListObjectsVersion string `mapstructure:"list_objects_version" yaml:"list_objects_version"`
BucketLookupType string `mapstructure:"bucket_lookup_type" yaml:"bucket_lookup_type"`
PartSize uint64 `mapstructure:"part_size" yaml:"part_size"`
SSEConfig SSEConfig `mapstructure:"sse_config" yaml:"sse_config"`
}
S3Config 对象存储 S3 的标准配置
type SSEConfig ¶ added in v0.3.2
type SSEConfig struct {
Type string `mapstructure:"type" yaml:"type"`
KMSKeyID string `mapstructure:"kms_key_id" yaml:"kms_key_id"`
KMSEncryptionContext map[string]string `mapstructure:"kms_encryption_context" yaml:"kms_encryption_context"`
EncryptionKey string `mapstructure:"encryption_key" yaml:"encryption_key"`
}
SSEConfig 用于配置对象存储服务端加密 https://docs.aws.amazon.com/kms/latest/developerguide/services-s3.html#s3-encryption-context
type SaramaConfig ¶
type SaramaConfig struct {
Net struct {
// 默认:5
MaxOpenRequests int `mapstructure:"max_open_requests"`
// 以下默认:30s
DialTimeout time.Duration `mapstructure:"dial_timeout"`
ReadTimeout time.Duration `mapstructure:"read_timeout"`
WriteTimeout time.Duration `mapstructure:"write_timeout"`
TLS struct {
// 默认:false
Enable bool `mapstructure:"enable"`
} `mapstructure:"tls"`
SASL struct {
Enable bool `mapstructure:"enable"`
Mechanism string `mapstructure:"mechanism"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
} `mapstructure:"sasl"`
KeepAlive time.Duration `mapstructure:"keep_alive"`
} `mapstructure:"net"`
Metadata struct {
// 获取元数据的策略
Retry struct {
// 当集群处于leader选举时最大重试次数,默认:3
Max int `mapstructure:"max"`
// 当集群处于leader选举重试的等扽时间,默认:250ms
Backoff time.Duration `mapstructure:"backoff"`
} `mapstructure:"retry"`
// 后台与集群同步metadata的间隔,默认: 10m
RefreshFrequency time.Duration `mapstructure:"refresh_frequency"`
// 是否为所有topic维护元数据,默认: true
Full bool `mapstructure:"full"`
// 等待metadata响应的超时时间,默认禁用表示失败则继续重试
// Net.[Dial|Read]Timeout * BrokerCount * (Metadata.Retry.Max + 1) + Metadata.Retry.Backoff * Metadata.Retry.Max
Timeout time.Duration `mapstructure:"timeout"`
// 如果提供的topic不存在是否允许自动创建(前提是集群配置可允许该操作),默认:true
AllowAutoTopicCreation bool `mapstructure:"allow_auto_topic_creation"`
} `mapstructure:"metadata"`
// 生产者相关配置
Producer struct {
// 允许的最大消息大小,最好等于集群配置的:message.max.bytes,默认:1000000
MaxMessageBytes int `mapstructure:"max_message_bytes"`
// 消息生产被集群接收的策略,主要影响是否会丢消息与性能,默认:1
// 设置为0: 生产者不等扽集群的响应,继续下一条
// 设置为1: 生成者等待leader响应,然后在继续下一条
// 设置为-1: 生产者必须等待所有"in-sync"副本响应完成,继续下一条,这个副本由: min.insync.replicas 决定
RequiredAcks int16 `mapstructure:"required_acks"`
// 生产者等扽响应的最长时间,当RequiredAcks设置大于1时才有效,等同于`request.timeout.ms`,默认:10s
Timeout time.Duration `mapstructure:"timeout"`
// 生产的消息使用的压缩算法,默认不压缩,默认:0
Compression int8 `mapstructure:"compression"`
// 压缩的等级,依赖具体压缩算法
CompressionLevel int `mapstructure:"commpression_level"`
// 如果启用,生产者将确保每个消息只写入一个副本。
Idempotent bool `mapstructure:"idempotent"`
// 消息响应成功或失败是否写入channel里,如果写入则必须被消费,否则可能出现死锁
Return struct {
// 成功的消息是否记录,默认:false
Successes bool `mapstructure:"successes"`
// 失败的消息是否记录,默认:true
Errors bool `mapstructure:"errors"`
} `mapstructure:"return"`
// 生产者达到以下阈值时触发打包消息发送至集群
Flush struct {
// 最大值被 sarama.MaxRequestSiz 限制,值:100 * 1024 * 1024
Bytes int `mapstructure:"bytes"`
// 消息数量阈值,最大限制通过以下MaxMessages控制
Messages int `mapstructure:"messages"`
// 等待时间阈值
Frequency time.Duration `mapstructure:"frequency"`
// 在单一请求broker时允许的最大消息数,设置为0则不限制
MaxMessages int `mapstructure:"max_messages"`
} `mapstructure:"flush"`
// 生产消息失败的重试策略
Retry struct {
// 最大重试次数,等同于jvm的:message.send.max.retries,默认:3
Max int `mapstructure:"max"`
// 重试失败之间等待间隔,等同于jvm的:retry.backoff.ms,默认值:100ms
Backoff time.Duration `mapstructure:"backoff"`
} `mapstructure:"retry"`
} `mapstructure:"producer"`
// 消费者相关配置
Consumer struct {
Group struct {
Session struct {
// 当broker端未收到消费者的心跳包,超过该时间间隔,则broker认为该消费者离线,将进行重均衡,默认:10s
// 该值必须在broker配置`group.min.session.timeout.ms`与`group.max.session.timeout.ms`之间
Timeout time.Duration `mapstructure:"timeout"`
} `mapstructure:"session"`
Heartbeat struct {
// kafka协调者预期的心跳间隔,用于确保消费者session处于活跃状态,值必须小于session.timeout,默认:3s
// 一般建议设置为session.timeout的3分之一
Interval time.Duration `mapstructure:"interval"`
} `mapstructure:"heartbeat"`
Rebalance struct {
// topic分区分配给消费者的策略,支持:range, roundrobin, sticky,默认:range
// range: 标识使用范围分区分配策略的策略
// roundrobin: 标识使用循环分区分配策略的策略
// sticky: 标识使用粘性分区分配策略的策略
Strategy string `mapstructure:"strategy"`
// 重均衡开始后,消费者加入群组的最大允许时间,默认:60s
Timeout time.Duration `mapstructure:"timeout"`
Retry struct {
// 最大重试次数,默认:4
Max int `mapstructure:"max"`
// 重试失败之间等待间隔,默认:2s
Backoff time.Duration `mapstructure:"backoff"`
} `mapstructure:"retry"`
} `mapstructure:"rebalance"`
} `mapstructure:"group"`
// 读取分区失败的重试
Retry struct {
// 重试失败之间等待间隔,默认:2s
Backoff time.Duration `mapstructure:"backoff"`
} `mapstructure:"retry"`
// 控制每个请求所拉取数据的大小,单位bytes
Fetch struct {
// 必须等待的最小消息大小,不要设置为0,等同于jvm `fetch.min.bytes`,默认:1
Min int32 `mapstructure:"min"`
// 每请求从broker获取的消息大小,默认:1MB
// 尽量大于你消息的大部分大小,否则还要做额外的切割,等同于jvm `fetch.message.max.bytes`
Default int32 `mapstructure:"default"`
// 每请求可最大获取的消息大小,值为0表示不限制,等同于jvm `fetch.message.max.bytes`,默认:0
Max int32 `mapstructure:"max"`
} `mapstructure:"fetch"`
// broker在等待消息达到 Consumer.Fetch.Min 大小的最大时间,不要设置为0,默认:250ms
// 建议在 100-500ms,等同于jvm `fetch.wait.max.ms`
MaxWaitTime time.Duration `mapstructure:"max_wait_time"`
// 消费者为用户处理消息所需的最长时间,如果写入消息通道所需的时间超过此时间,则该分区将停止获取更多消息,直到可以再次继续。
// 由于消息通道已缓冲,因此实际宽限时间为 (MaxProcessingTime * ChannelBufferSize),默认:100ms
MaxProcessingTime time.Duration `mapstructure:"max_processing_time"`
// 消息响应成功或失败是否写入channel里,如果写入则必须被消费,否则可能出现死锁
Return struct {
// 失败的消息是否记录,默认:false
Errors bool `mapstructure:"errors"`
} `mapstructure:"return"`
// 控制如何提交消费offset
Offsets struct {
AutoCommit struct {
// 是否自动更新,默认:true
Enable bool `mapstructure:"enable"`
// 自动更新频率,默认:1s
Interval time.Duration `mapstructure:"interval"`
} `mapstructure:"auto_commit"`
// OffsetNewest=-1 代表访问 commit 位置的下一条消息
// OffsetOldest=-2 消费者可以访问到的 topic 里的最早的消息
Initial int64 `mapstructure:"initial"`
Retention time.Duration `mapstructure:"retention"`
// 提交offset失败的重试
Retry struct {
// 最大重试次数,默认:3
Max int `mapstructure:"max"`
} `mapstructure:"retry"`
} `mapstructure:"offsets"`
// 消费隔离级别,ReadUncommitted 或 ReadCommitted,默认:ReadUncommitted
// ReadUncommitted: 可以读取到未提交的数据(报错终止前的数据)
// ReadCommitted: 生产者已提交的数据才能读取到
IsolationLevel int8 `mapstructure:"isolation_level"`
} `mapstructure:"consumer"`
// 标识该消费者
ClientID string `mapstructure:"client_id"`
// 机柜标识,见 'broker.rack'
RackID string `mapstructure:"rack_id"`
// 默认:256
ChannelBufferSize int `mapstructure:"chnnel_buffer_size"`
Version string `mapstructure:"version"`
}
SaramaConfig 用于kafka客户端配置,结构等同于sarama类库 https://pkg.go.dev/github.com/Shopify/sarama#Config
func (*SaramaConfig) Parse ¶
func (s *SaramaConfig) Parse() *sarama.Config
Parse 解析为 https://pkg.go.dev/github.com/Shopify/sarama#Config
type SecurityConfig ¶
type SecurityConfig struct {
Enable bool `mapstructure:"enable"`
Authentication *Authentication `mapstructure:"authentication"`
Authorization *Authorization `mapstructure:"authorization"`
// contains filtered or unexported fields
}
SecurityConfig 安全配置,对接认证、鉴权
type ServicesConfig ¶
type ServicesConfig struct {
RootPath string `mapstructure:"root_path"`
Namespace string `mapstructure:"namespace"`
ServiceCode string `mapstructure:"service_code"`
APIEndpoint string `mapstructure:"api_endpoint"`
// Deprecated: 使用 GRPCService 代替,优先级低于 GRPCService 配置
GRPCAddress string `mapstructure:"grpc_address"`
// Deprecated: 使用 HTTPService 代替,优先级低于 HTTPService 配置
HTTPAddress string `mapstructure:"http_address"`
PublicAddress string `mapstructure:"public_address"`
GRPCService *GRPCService `mapstructure:"grpc_service"`
HTTPService *HTTPService `mapstructure:"http_service"`
Integrations struct {
GRPC struct {
Admin *bool `mapstructure:"admin"`
}
} `mapstructure:"integrations"`
SecurityKey string `mapstructure:"security_key"`
// contains filtered or unexported fields
}
ServicesConfig 基础服务配置,用于设定命名空间、注册的路径、监听的地址等
type TLSAutoConfig ¶ added in v0.3.5
type TLSAutoConfig struct {
ACME *struct {
Server string `mapstructure:"server"`
Email string `mapstructure:"email"`
Domains []string `mapstructure:"domains"`
CacheDir string `mapstructure:"cache_dir"`
} `mapstructure:"acme"`
SPIFFE *struct {
Agent string `mapstructure:"agent"`
}
}
TLSAutoConfig 用于证书的自动化生成
type TLSConfig ¶
type TLSConfig struct {
// 进行 TLS 握手时,客户端会检查服务器返回的证书中的主机名与客户端期望的主机名是否匹配
// 如果设置了 ServerName,那么客户端会使用该字段的值来验证服务器证书的主机名
// 如果设置了 InsecureSkipVerify 为 true,则跳过主机名验证
ServerName string `mapstructure:"server_name" yaml:"server_name"`
// 默认情况下,客户端会验证服务器的证书链和主机名,以确保建立安全的 TLS 连接,避免被中间人攻击
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify" yaml:"insecure_skip_verify"`
// 最低支持的 tls 版本,取值范围:TLSv1 TLSv1.1 TLSv1.2 TLSv1.3
MinVersion string `mapstructure:"min_version" yaml:"min_version"`
// 最高支持的 tls 版本,取值范围:TLSv1 TLSv1.1 TLSv1.2 TLSv1.3
MaxVersion string `mapstructure:"max_version" yaml:"max_version"`
// 用于定义客户端在验证服务器证书时使用的根证书,一般在自签证书时使用
CAFile string `mapstructure:"ca_file" yaml:"ca_file"`
// 客户端证书公钥
CertFile string `mapstructure:"cert_file" yaml:"cert_file"`
// 客户端证书私钥
KeyFile string `mapstructure:"key_file" yaml:"key_file"`
}
TLSConfig 用于配置客户端与服务端 tls 相关行为
type TelemetryConfig ¶ added in v0.3.3
type TelemetryConfig struct {
Metrics *TelemetryMetric `mapstructure:"metrics"`
Traces *TelemetryTrace `mapstructure:"traces"`
}
TelemetryConfig xx
type TelemetryMetric ¶ added in v0.3.3
type TelemetryMetric struct {
// 为所有暴露的指标添加前缀
Namespace string `mapstructure:"namespace"`
// 性能数据上报频率,默认1分钟,单位:秒
PushInterval int `mapstructure:"push_interval"`
// 是否启用 Exporters 配置下的 otel otelhttp logging prometheus
Exporters ExporterEnable `mapstructure:"exporter_enable"`
}
TelemetryMetric 性能指标个性配置
type TelemetryTrace ¶ added in v0.3.3
type TelemetryTrace struct {
// 给定一个 0 至 1 之间的分数决定采样频率
SampleRatio *float64 `mapstructure:"sample_ratio"`
// 是否启用 Exporters 配置下的 otel otelhttp logging
Exporters ExporterEnable `mapstructure:"exporter_enable"`
// 记录特殊字段,默认不开启
LogFields struct {
HTTPRequest bool `mapstructure:"http_request"`
HTTPResponse bool `mapstructure:"http_response"`
} `mapstructure:"log_fields"`
// 过滤器,用于过滤不需要追踪的请求
Filters []struct {
Method string `mapstructure:"method"`
URLPath string `mapstructure:"url_path"`
} `mapstructure:"filters"`
}
TelemetryTrace 链路跟踪个性配置
type URLStyle ¶ added in v0.3.2
type URLStyle string
URLStyle 对象存储访问的 url 风格类型 https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAPI.html
type WebInterfaceConfig ¶ added in v0.3.5
type WebInterfaceConfig struct {
Enabled *bool `mapstructure:"enabled"` // 是否启用该服务
Embedded *bool `mapstructure:"embedded"` // 是否嵌入到编译的二进制
HandleURL string `mapstructure:"handle_url"` // 注册服务对应的 URL 地址
Tracing bool `mapstructure:"tracing"` // 是否接入可观测性的链路跟踪服务
}
WebInterfaceConfig 表示前端界面组件配置
type XDGSCRAMClient ¶
type XDGSCRAMClient struct {
*scram.Client
*scram.ClientConversation
scram.HashGeneratorFcn
}
XDGSCRAMClient struct to perform SCRAM conversation
func (*XDGSCRAMClient) Begin ¶
func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error)
Begin starts SCRAM conversation
func (*XDGSCRAMClient) Done ¶
func (x *XDGSCRAMClient) Done() bool
Done completes SCRAM conversation