Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- type ConnectionEvent
- type Controller
- func (c *Controller) Deregister(ctx context.Context) error
- func (c *Controller) Drain(ctx context.Context, gracePeriod string) error
- func (c *Controller) ObserveEvent(event ConnectionEvent)
- func (c *Controller) OnConnected(ctx context.Context) error
- func (c *Controller) OnDisconnected()
- func (c *Controller) RecordError(err error)
- func (c *Controller) Status() Status
- type DeregisterRequest
- type DescriptorProvider
- type DrainRequest
- type ErrorHandler
- type EventSource
- type GRPCDescriptorOptions
- type JSONHTTPClient
- type KernelInfo
- type LifecycleHookOptions
- type LifecycleHooks
- type LifecycleOptions
- type LifecycleRunError
- type LocalRuntime
- type LocalRuntimeOptions
- type ManagedServer
- type ManagedServerOptions
- type ManagedServerRunError
- type RegisterReplayError
- type RegisterRequest
- type Runner
- type ServeFunc
- type ServiceKernel
- type ServiceLifecycle
- func NewServiceLifecycle(options LifecycleOptions) (*ServiceLifecycle, error)
- func NewServiceLifecycleFromGRPC(descriptorOptions GRPCDescriptorOptions, runtimeOptions LocalRuntimeOptions, ...) (*ServiceLifecycle, error)
- func NewServiceLifecycleFromServiceRegistration(descriptor ServiceRegistration, runtimeOptions LocalRuntimeOptions, ...) (*ServiceLifecycle, error)
- type ServiceMeta
- type ServiceNode
- type ServiceOptions
- type ServiceRegistration
- type ServiceRegistrationProvider
- type ShutdownFunc
- type Status
- type WatchEventParseError
- type WatchHTTPStatusError
- type WatchSource
Constants ¶
const ( // DefaultAdminBaseURL 表示业务服务默认访问的本机 sidecar-agent 管理地址。 DefaultAdminBaseURL = "http://127.0.0.1:15010" // DefaultWatchPath 表示 sidecar-agent 提供的默认 watch 路径。 DefaultWatchPath = "/watch" // DefaultRequestTimeout 表示 register、drain、deregister 的默认请求超时。 DefaultRequestTimeout = 3 * time.Second // DefaultReconnectInterval 表示 watch 断开后的默认重连间隔。 DefaultReconnectInterval = time.Second )
const ( // ManagedServerStageLifecycle 表示 sidecar 生命周期桥接阶段。 ManagedServerStageLifecycle = "lifecycle" // ManagedServerStageServe 表示业务服务阻塞运行阶段。 ManagedServerStageServe = "serve" // ManagedServerStageShutdown 表示业务服务优雅关闭阶段。 ManagedServerStageShutdown = "shutdown" // ManagedServerStageAgentShutdown 表示 agent 摘流与注销阶段。 ManagedServerStageAgentShutdown = "agent_shutdown" )
const ( // ConnectionEventTypeConnected 表示与本机 sidecar-agent 的 watch 流已建立。 ConnectionEventTypeConnected = "connected" // ConnectionEventTypeHeartbeat 表示 watch 流仍然存活,但不要求业务侧执行 register 重放。 ConnectionEventTypeHeartbeat = "heartbeat" // ConnectionEventTypeDisconnected 表示 watch 流已断开,等待后续重连。 ConnectionEventTypeDisconnected = "disconnected" )
Variables ¶
var ( // ErrWatchURLRequired 表示业务侧未提供本地 `/watch` 地址。 ErrWatchURLRequired = errors.New("watch url is required") // ErrWatchStreamClosed 表示当前 watch 流已由服务端关闭,调用方应进入下一轮重连。 ErrWatchStreamClosed = errors.New("watch stream closed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Register 负责把当前服务注册到本机 sidecar-agent。
Register(ctx context.Context, request RegisterRequest) error
// Drain 负责把当前服务切换到摘流状态。
Drain(ctx context.Context, request DrainRequest) error
// Deregister 负责把当前服务从本机 sidecar-agent 注销。
Deregister(ctx context.Context, request DeregisterRequest) error
}
Client 抽象本机 sidecar-agent 的最小交互能力。
type ConnectionEvent ¶
type ConnectionEvent struct {
// Type 表示事件类型,例如 connected、heartbeat、disconnected。
Type string
// Connected 表示当前事件是否意味着连接已建立。
Connected bool
// EventId 表示服务端 SSE 事件 ID,便于后续排障与协议增强。
EventId string
// Message 保存服务端事件说明文本。
Message string
// Service 表示当前发出 watch 事件的服务名。
Service string
// Status 表示 sidecar 当前运行态摘要,例如 ready、starting、degraded。
Status string
// LifecycleState 表示 sidecar 当前生命周期阶段。
LifecycleState string
// Ready 表示 sidecar 主链当前是否 ready;nil 表示服务端未提供该信息。
Ready *bool
// GeneratedAt 表示该事件在服务端生成的时间。
GeneratedAt *time.Time
// Err 保存连接断开或处理失败时的上下文错误。
Err error
}
ConnectionEvent 描述本机 agent 连接状态变化事件。
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller 负责在业务服务侧缓存注册描述,并在连接恢复后重放 register。
func NewController ¶
func NewController(client Client, provider DescriptorProvider) (*Controller, error)
NewController 创建一个新的业务侧 agent 联动控制器。
func (*Controller) Deregister ¶
func (c *Controller) Deregister(ctx context.Context) error
Deregister 使用最近一次成功注册的服务描述发起注销。
func (*Controller) Drain ¶
func (c *Controller) Drain(ctx context.Context, gracePeriod string) error
Drain 使用最近一次成功注册的服务描述发起摘流。
func (*Controller) ObserveEvent ¶ added in v0.0.8
func (c *Controller) ObserveEvent(event ConnectionEvent)
ObserveEvent 记录最近一次收到的 watch 事件,供业务侧调试恢复链路使用。
func (*Controller) OnConnected ¶
func (c *Controller) OnConnected(ctx context.Context) error
OnConnected 在本机 agent 连接建立或恢复时重放 register。
func (*Controller) OnDisconnected ¶
func (c *Controller) OnDisconnected()
OnDisconnected 在本机 agent 连接断开时把控制器状态标记为未连接。
func (*Controller) RecordError ¶ added in v0.0.8
func (c *Controller) RecordError(err error)
RecordError 把最近一次运行错误写入状态快照。
type DeregisterRequest ¶
type DeregisterRequest struct {
// Name 表示逻辑服务名。
Name string `json:"name"`
// Port 表示业务服务监听端口。
Port int `json:"port"`
}
DeregisterRequest 表示业务服务向本机 sidecar-agent 发起的注销请求。
type DescriptorProvider ¶
type DescriptorProvider interface {
// BuildRegisterRequest 返回当前业务服务完整注册描述。
BuildRegisterRequest(ctx context.Context) (RegisterRequest, error)
}
DescriptorProvider 抽象业务服务注册描述的构造能力。
type DrainRequest ¶
type DrainRequest struct {
// Name 表示逻辑服务名。
Name string `json:"name"`
// Port 表示业务服务监听端口。
Port int `json:"port"`
// GracePeriod 表示摘流宽限期。
GracePeriod string `json:"grace_period"`
}
DrainRequest 表示业务服务向本机 sidecar-agent 发起的摘流请求。
type EventSource ¶
type EventSource interface {
// Subscribe 返回一个持续输出连接事件的只读通道。
Subscribe(ctx context.Context) (<-chan ConnectionEvent, error)
}
EventSource 抽象本地 agent 连接事件来源。
type GRPCDescriptorOptions ¶
type GRPCDescriptorOptions struct {
// AppID 表示应用标识。
AppId string
// AppName 表示应用名称;为空时回退到 ServiceName。
AppName string
// ServiceName 表示逻辑服务名。
ServiceName string
// Namespace 表示命名空间。
Namespace string
// DNS 表示统一服务域名。
DNS string
// Env 表示运行环境。
Env string
// Port 表示业务监听端口。
Port int
// Protocol 表示业务协议。
Protocol string
// Version 表示业务版本号。
Version string
// ServiceOptions 表示业务服务当前的裸机接入配置。
ServiceOptions *ServiceOptions
// RawServices 表示业务已注册的 gRPC ServiceDesc 集合。
RawServices []*grpc.ServiceDesc
}
GRPCDescriptorOptions 描述如何从 gRPC 服务描述直接构造 agent 注册信息。
type JSONHTTPClient ¶
type JSONHTTPClient struct {
// contains filtered or unexported fields
}
JSONHTTPClient 提供一个基于 JSON over HTTP 的本地 agent client 实现。
func NewJSONHTTPClient ¶
func NewJSONHTTPClient(baseURL string, timeout time.Duration) *JSONHTTPClient
NewJSONHTTPClient 创建一个新的本地 HTTP JSON client。
func (*JSONHTTPClient) Deregister ¶
func (c *JSONHTTPClient) Deregister(ctx context.Context, request DeregisterRequest) error
Deregister 通过本机管理接口发起注销。
func (*JSONHTTPClient) Drain ¶
func (c *JSONHTTPClient) Drain(ctx context.Context, request DrainRequest) error
Drain 通过本机管理接口发起摘流。
func (*JSONHTTPClient) Register ¶
func (c *JSONHTTPClient) Register(ctx context.Context, request RegisterRequest) error
Register 通过本机管理接口注册当前服务。
type KernelInfo ¶
type KernelInfo struct {
// Language 表示业务服务使用的开发语言。
Language string `json:"language"`
// Version 表示业务服务运行时或框架版本。
Version string `json:"version"`
}
KernelInfo 描述业务服务运行时信息。
type LifecycleHookOptions ¶ added in v0.0.8
type LifecycleHookOptions struct {
// Lifecycle 表示已经组装完成的业务生命周期桥接对象。
Lifecycle *ServiceLifecycle
// OnError 用于处理后台 watch 与 register 重放阶段的异步错误。
OnError ErrorHandler
}
LifecycleHookOptions 描述如何把业务生命周期桥接对象接到宿主框架的启动钩子。
type LifecycleHooks ¶ added in v0.0.8
type LifecycleHooks struct {
// contains filtered or unexported fields
}
LifecycleHooks 提供适合宿主框架 start/stop 钩子直接调用的适配层。
func NewLifecycleHooks ¶ added in v0.0.8
func NewLifecycleHooks(options LifecycleHookOptions) (*LifecycleHooks, error)
NewLifecycleHooks 创建一个新的宿主钩子适配器。
func (*LifecycleHooks) OnStart ¶ added in v0.0.8
func (h *LifecycleHooks) OnStart(ctx context.Context) error
OnStart 供宿主框架在启动阶段调用,内部会启动后台 watch 与自动重放循环。
func (*LifecycleHooks) OnStop ¶ added in v0.0.8
func (h *LifecycleHooks) OnStop(ctx context.Context) error
OnStop 供宿主框架在关闭阶段调用,内部统一执行 drain + deregister。
func (*LifecycleHooks) Status ¶ added in v0.0.8
func (h *LifecycleHooks) Status() Status
Status 返回当前钩子适配层看到的最新运行状态。
type LifecycleOptions ¶
type LifecycleOptions struct {
// Runtime 表示已经组装完成的本地 agent 运行时。
Runtime *LocalRuntime
// GracePeriod 表示业务服务优雅下线时使用的默认摘流宽限期。
GracePeriod string
}
LifecycleOptions 描述业务服务接入 agent 生命周期桥接时的最小参数。
type LifecycleRunError ¶ added in v0.0.8
type LifecycleRunError struct {
// Err 表示底层运行失败原因。
Err error
}
LifecycleRunError 表示本地 agent 生命周期后台循环运行失败。
func (*LifecycleRunError) Error ¶ added in v0.0.8
func (e *LifecycleRunError) Error() string
Error 返回可读错误信息。
func (*LifecycleRunError) Unwrap ¶ added in v0.0.8
func (e *LifecycleRunError) Unwrap() error
Unwrap 返回底层错误。
type LocalRuntime ¶
type LocalRuntime struct {
// Client 负责发起 register / drain / deregister 请求。
Client *JSONHTTPClient
// Source 负责把本地 `/watch` 连接转换成连接事件流。
Source *WatchSource
// Controller 负责缓存注册描述并在连接恢复时重放 register。
Controller *Controller
// Runner 负责驱动事件流与 register 重放过程。
Runner *Runner
}
LocalRuntime 把本地 HTTP client、watch 事件源、控制器与运行器组装成一个整体。
func NewLocalRuntime ¶
func NewLocalRuntime(provider DescriptorProvider, options LocalRuntimeOptions) (*LocalRuntime, error)
NewLocalRuntime 使用最小参数组装一套可直接接入业务服务的本地运行时。
func NewLocalRuntimeFromServiceRegistration ¶
func NewLocalRuntimeFromServiceRegistration(descriptor ServiceRegistration, options LocalRuntimeOptions) (*LocalRuntime, error)
NewLocalRuntimeFromServiceRegistration 使用 go-micro 服务描述直接组装本地 agent 运行时。
func (*LocalRuntime) Deregister ¶
func (r *LocalRuntime) Deregister(ctx context.Context) error
Deregister 通过控制器复用最近一次注册描述发起注销。
func (*LocalRuntime) Drain ¶
func (r *LocalRuntime) Drain(ctx context.Context, gracePeriod string) error
Drain 通过控制器复用最近一次注册描述发起摘流。
type LocalRuntimeOptions ¶
type LocalRuntimeOptions struct {
// BaseURL 表示本机 sidecar-agent 管理接口前缀。
BaseURL string
// WatchURL 表示本机 sidecar-agent 的长连接 watch 地址。
WatchURL string
// RequestTimeout 表示 register / drain / deregister 请求超时。
RequestTimeout time.Duration
// ReconnectInterval 表示 watch 断开后的重连间隔。
ReconnectInterval time.Duration
// OnError 用于统一处理 watch 与 register 重放过程中的错误。
OnError ErrorHandler
}
LocalRuntimeOptions 描述业务服务接入本机 sidecar-agent 的最小参数。
func DefaultLocalRuntimeOptions ¶
func DefaultLocalRuntimeOptions(baseURL string) LocalRuntimeOptions
DefaultLocalRuntimeOptions 返回一份可直接接入业务服务的默认本地运行时参数。
type ManagedServer ¶
type ManagedServer struct {
// contains filtered or unexported fields
}
ManagedServer 把业务服务运行逻辑与 sidecar-agent 生命周期收敛成一个统一入口。
func NewManagedServer ¶
func NewManagedServer(options ManagedServerOptions) (*ManagedServer, error)
NewManagedServer 创建一个新的业务服务托管器。
type ManagedServerOptions ¶
type ManagedServerOptions struct {
// Lifecycle 表示 sidecar-agent 生命周期桥接对象。
Lifecycle *ServiceLifecycle
// Serve 表示业务服务真正的阻塞运行入口。
Serve ServeFunc
// Shutdown 表示业务服务优雅关闭入口;可为空。
Shutdown ShutdownFunc
}
ManagedServerOptions 描述如何把业务服务运行逻辑与 agent 生命周期桥接到一起。
type ManagedServerRunError ¶ added in v0.0.8
ManagedServerRunError 表示托管服务在某个阶段失败。
func (*ManagedServerRunError) Error ¶ added in v0.0.8
func (e *ManagedServerRunError) Error() string
Error 返回带阶段信息的错误文本。
func (*ManagedServerRunError) Unwrap ¶ added in v0.0.8
func (e *ManagedServerRunError) Unwrap() error
Unwrap 返回底层错误。
type RegisterReplayError ¶ added in v0.0.8
type RegisterReplayError struct {
// ServiceName 表示当前重放失败的服务名。
ServiceName string
// ServicePort 表示当前重放失败的服务端口。
ServicePort int
// Err 表示底层 register 调用失败原因。
Err error
}
RegisterReplayError 表示业务侧在连接恢复后重放 register 时失败。
func (*RegisterReplayError) Error ¶ added in v0.0.8
func (e *RegisterReplayError) Error() string
Error 返回带服务上下文的可读错误信息。
func (*RegisterReplayError) Unwrap ¶ added in v0.0.8
func (e *RegisterReplayError) Unwrap() error
Unwrap 返回底层错误,便于调用方做 errors.Is / errors.As。
type RegisterRequest ¶
type RegisterRequest struct {
// AppID 表示应用标识。
AppID string `json:"app_id"`
// AppName 表示应用名称。
AppName string `json:"app_name"`
// Name 表示逻辑服务名。
Name string `json:"name"`
// Namespace 表示命名空间。
Namespace string `json:"namespace"`
// Port 表示业务服务监听端口。
Port int `json:"port"`
// DNS 表示业务服务统一域名。
DNS string `json:"dns"`
// Env 表示业务服务所属环境。
Env string `json:"env"`
// Weight 表示实例权重。
Weight int `json:"weight"`
// Protocol 表示服务协议。
Protocol string `json:"protocol"`
// Kernel 表示业务服务运行时信息。
Kernel KernelInfo `json:"kernel"`
// Methods 表示业务服务暴露的方法列表。
Methods []string `json:"methods"`
// Version 表示业务版本号。
Version string `json:"version"`
}
RegisterRequest 表示业务服务向本机 sidecar-agent 发起的注册请求。
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner 负责把连接事件转换成 register 重放动作。
func NewRunner ¶
func NewRunner(source EventSource, controller *Controller, onError ErrorHandler) (*Runner, error)
NewRunner 创建一个新的连接事件驱动运行器。
type ServiceKernel ¶
ServiceKernel 描述业务服务运行时内核信息。
type ServiceLifecycle ¶
type ServiceLifecycle struct {
// contains filtered or unexported fields
}
ServiceLifecycle 把本地 agent 运行时包装成更适合业务启动与退出阶段接入的对象。
func NewServiceLifecycle ¶
func NewServiceLifecycle(options LifecycleOptions) (*ServiceLifecycle, error)
NewServiceLifecycle 基于已组装好的本地运行时创建业务生命周期桥接对象。
func NewServiceLifecycleFromGRPC ¶
func NewServiceLifecycleFromGRPC(descriptorOptions GRPCDescriptorOptions, runtimeOptions LocalRuntimeOptions, lifecycleOptions LifecycleOptions) (*ServiceLifecycle, error)
NewServiceLifecycleFromGRPC 使用 gRPC ServiceDesc 与 ServiceOptions 直接创建业务生命周期桥接对象。
func NewServiceLifecycleFromServiceRegistration ¶
func NewServiceLifecycleFromServiceRegistration(descriptor ServiceRegistration, runtimeOptions LocalRuntimeOptions, lifecycleOptions LifecycleOptions) (*ServiceLifecycle, error)
NewServiceLifecycleFromServiceRegistration 允许业务直接基于 go-micro 服务描述组装生命周期桥接对象。
func (*ServiceLifecycle) Deregister ¶
func (l *ServiceLifecycle) Deregister(ctx context.Context) error
Deregister 对当前服务发起注销。
func (*ServiceLifecycle) Drain ¶
func (l *ServiceLifecycle) Drain(ctx context.Context) error
Drain 使用默认宽限期对当前服务发起摘流。
func (*ServiceLifecycle) Shutdown ¶
func (l *ServiceLifecycle) Shutdown(ctx context.Context) error
Shutdown 先摘流再注销,适合业务服务优雅退出路径直接调用。
func (*ServiceLifecycle) Start ¶
func (l *ServiceLifecycle) Start(ctx context.Context) <-chan error
Start 在后台启动本地 watch 运行循环,并返回异步错误通道。
func (*ServiceLifecycle) Status ¶
func (l *ServiceLifecycle) Status() Status
Status 返回当前生命周期桥接对象的最新状态快照。
type ServiceMeta ¶
type ServiceMeta struct {
AppId string `json:"app_id"`
InstanceId string `json:"instance_id"`
Version string `json:"version"`
Env string `json:"env"`
}
ServiceMeta 描述业务服务在裸机场景下的最小身份信息。
type ServiceNode ¶
type ServiceNode struct {
ProtoCount int `json:"proto_count"`
Weight int `json:"weight"`
RunDate string `json:"run_date"`
Methods map[string]bool `json:"methods"`
Kernel *ServiceKernel `json:"kernel"`
Meta *ServiceMeta `json:"meta"`
}
ServiceNode 描述业务服务在裸机场景下的最小注册节点信息。
type ServiceOptions ¶
type ServiceOptions struct {
InstanceId string `json:"instance_id"`
Namespace string `json:"namespace"`
Kernel *ServiceKernel `json:"kernel"`
MaxRetry uint32 `json:"max_retry"`
TTL uint32 `json:"ttl"`
Weight int `json:"weight"`
}
ServiceOptions 描述业务服务接入本机 sidecar-agent 时的基础选项。
type ServiceRegistration ¶
type ServiceRegistration struct {
// AppId 表示应用标识;为空时优先回退到 Node.Meta.AppID。
AppId string
// AppName 表示应用名称;为空时回退到 ServiceName。
AppName string
// ServiceName 表示逻辑服务名。
ServiceName string
// Namespace 表示命名空间。
Namespace string
// DNS 表示统一服务域名。
DNS string
// Env 表示运行环境。
Env string
// Port 表示业务监听端口。
Port int
// Protocol 表示当前服务协议。
Protocol string
// Version 表示业务版本号。
Version string
// Weight 表示实例权重;为空时优先回退到 Node.Weight。
Weight int
// Node 表示业务服务当前的注册节点信息。
Node *ServiceNode
}
ServiceRegistration 描述如何把 go-micro 的服务信息映射成 sidecar-agent register 请求。
func NewServiceRegistrationFromGRPC ¶
func NewServiceRegistrationFromGRPC(options GRPCDescriptorOptions) (ServiceRegistration, error)
NewServiceRegistrationFromGRPC 使用 gRPC ServiceDesc 与 ServiceOptions 构造服务注册描述。
type ServiceRegistrationProvider ¶
type ServiceRegistrationProvider struct {
// contains filtered or unexported fields
}
ServiceRegistrationProvider 负责把 go-micro 的服务节点信息转换成 agent 注册描述。
func NewServiceRegistrationProvider ¶
func NewServiceRegistrationProvider(descriptor ServiceRegistration) (*ServiceRegistrationProvider, error)
NewServiceRegistrationProvider 创建一个基于 go-micro 服务描述的 provider。
func (*ServiceRegistrationProvider) BuildRegisterRequest ¶
func (p *ServiceRegistrationProvider) BuildRegisterRequest(ctx context.Context) (RegisterRequest, error)
BuildRegisterRequest 生成 sidecar-agent 所需的标准注册请求。
type Status ¶
type Status struct {
// Connected 表示当前是否与本机 sidecar-agent 保持连接。
Connected bool
// Registered 表示最近一次 register 是否成功完成。
Registered bool
// LastServiceName 表示最近一次成功注册的服务名。
LastServiceName string
// LastServicePort 表示最近一次成功注册的服务端口。
LastServicePort int
// LastEventType 表示最近一次收到的 watch 事件类型。
LastEventType string
// LastEventId 表示最近一次收到的 SSE 事件 ID。
LastEventId string
// LastEventAt 表示最近一次事件的观测时间。
LastEventAt string
// LastConnectedAt 表示最近一次成功建立或恢复连接的时间。
LastConnectedAt string
// LastDisconnectedAt 表示最近一次断连的时间。
LastDisconnectedAt string
// DisconnectCount 表示运行期间累计收到的断连次数。
DisconnectCount int
// RegisterReplayCount 表示累计成功重放 register 的次数。
RegisterReplayCount int
// RegisterReplayFailureCount 表示累计 register 重放失败次数。
RegisterReplayFailureCount int
// LastErrorKind 表示最近一次错误的分类。
LastErrorKind string
// LastError 表示最近一次错误文本。
LastError string
// LastErrorAt 表示最近一次错误发生时间。
LastErrorAt string
}
Status 描述当前 agent 联动控制器的最新状态。
type WatchEventParseError ¶ added in v0.0.8
type WatchEventParseError struct {
// EventType 表示解析失败的事件类型。
EventType string
// EventId 表示服务端 SSE 事件 ID。
EventId string
// Payload 表示原始 data 内容,便于调试坏帧。
Payload string
// Err 表示底层 JSON 解析错误。
Err error
}
WatchEventParseError 表示 SSE 事件帧存在结构化载荷解析错误。
func (*WatchEventParseError) Error ¶ added in v0.0.8
func (e *WatchEventParseError) Error() string
Error 返回可读错误文本。
func (*WatchEventParseError) Unwrap ¶ added in v0.0.8
func (e *WatchEventParseError) Unwrap() error
Unwrap 返回底层解析错误。
type WatchHTTPStatusError ¶ added in v0.0.8
type WatchHTTPStatusError struct {
// StatusCode 表示 HTTP 状态码。
StatusCode int
// Status 表示原始 HTTP 状态文本。
Status string
}
WatchHTTPStatusError 表示 `/watch` 接口返回了非 200 状态码。
func (*WatchHTTPStatusError) Error ¶ added in v0.0.8
func (e *WatchHTTPStatusError) Error() string
Error 返回可读错误文本。
type WatchSource ¶
type WatchSource struct {
// contains filtered or unexported fields
}
WatchSource 基于 sidecar-agent 的 `/watch` 长连接接口输出连接事件。
func NewWatchSource ¶
func NewWatchSource(watchURL string, reconnectInterval time.Duration) *WatchSource
NewWatchSource 创建一个新的长连接事件源。
func (*WatchSource) Subscribe ¶
func (s *WatchSource) Subscribe(ctx context.Context) (<-chan ConnectionEvent, error)
Subscribe 启动后台重连循环,并把连接状态变化转换成事件流。