Documentation
¶
Index ¶
- Constants
- func NewExtension(opts ...ConfigOption) forge.Extension
- func NewExtensionWithConfig(config Config) forge.Extension
- type Backend
- type Config
- type ConfigOption
- func WithAppConfig(appConfig forge.AppConfig) ConfigOption
- func WithAutoDeregister(enabled bool) ConfigOption
- func WithBackend(backend string) ConfigOption
- func WithConfig(config Config) ConfigOption
- func WithConsul(address, token string) ConfigOption
- func WithEnabled(enabled bool) ConfigOption
- func WithEtcd(endpoints []string) ConfigOption
- func WithEureka(urls []string) ConfigOption
- func WithFARP(farp FARPConfig) ConfigOption
- func WithFARPAutoRegister(autoRegister bool) ConfigOption
- func WithFARPCapabilities(capabilities ...string) ConfigOption
- func WithFARPCollapseServiceTags(collapse bool) ConfigOption
- func WithFARPEnabled(enabled bool) ConfigOption
- func WithFARPEndpoints(endpoints FARPEndpointsConfig) ConfigOption
- func WithFARPExcludeInternalPaths(exclude bool) ConfigOption
- func WithFARPGatewayURL(url string) ConfigOption
- func WithFARPPathRules(rules ...farp.PathRule) ConfigOption
- func WithFARPSchemas(schemas ...FARPSchemaConfig) ConfigOption
- func WithFARPStrategy(strategy string) ConfigOption
- func WithHTTPHealthCheck(endpoint string, interval time.Duration) ConfigOption
- func WithHTTPPollInterval(d time.Duration) ConfigOption
- func WithHTTPSeeds(seeds ...string) ConfigOption
- func WithHTTPTimeout(d time.Duration) ConfigOption
- func WithHealthCheck(config HealthCheckConfig) ConfigOption
- func WithKubernetes(namespace string, inCluster bool) ConfigOption
- func WithMDNS(domain string) ConfigOption
- func WithMDNSBrowseTimeout(d time.Duration) ConfigOption
- func WithMDNSIPv6(enabled bool) ConfigOption
- func WithMDNSInterface(iface string) ConfigOption
- func WithMDNSServiceType(serviceType string) ConfigOption
- func WithMDNSServiceTypes(types ...string) ConfigOption
- func WithMDNSTTL(ttl uint32) ConfigOption
- func WithMDNSWatchInterval(d time.Duration) ConfigOption
- func WithService(service ServiceConfig) ConfigOption
- func WithServiceAddress(address string, port int) ConfigOption
- func WithServiceID(id string) ConfigOption
- func WithServiceMetadata(metadata map[string]string) ConfigOption
- func WithServiceName(name string) ConfigOption
- func WithServiceTags(tags ...string) ConfigOption
- func WithServiceVersion(version string) ConfigOption
- func WithWatch(services []string, onChange func([]*ServiceInstance)) ConfigOption
- type ConsulConfig
- type EtcdConfig
- type EurekaConfig
- type Extension
- func (e *Extension) Dependencies() []string
- func (e *Extension) Health(ctx context.Context) error
- func (e *Extension) LocalServiceID() string
- func (e *Extension) Register(app forge.App) error
- func (e *Extension) Run(ctx context.Context) error
- func (e *Extension) Service() *Service
- func (e *Extension) ServiceNode() *farpdiscovery.ServiceNode
- func (e *Extension) Shutdown(ctx context.Context) error
- func (e *Extension) Start(ctx context.Context) error
- func (e *Extension) Stop(ctx context.Context) error
- type FARPConfig
- type FARPEndpointsConfig
- type FARPLocationConfig
- type FARPSchemaConfig
- type HTTPConfig
- type HealthCheckConfig
- type HealthStatus
- type KubernetesConfig
- type LoadBalanceStrategy
- type MDNSConfig
- type SchemaPublisher
- func (p *SchemaPublisher) Close() error
- func (p *SchemaPublisher) GetManifest(ctx context.Context, instanceID string) (*farp.SchemaManifest, error)
- func (p *SchemaPublisher) GetMetadataForDiscovery(baseURL string) map[string]string
- func (p *SchemaPublisher) Publish(ctx context.Context, instanceID string) error
- type Service
- func (s *Service) Backend() Backend
- func (s *Service) Deregister(ctx context.Context, serviceID string) error
- func (s *Service) Discover(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
- func (s *Service) DiscoverHealthy(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
- func (s *Service) DiscoverWithTags(ctx context.Context, serviceName string, tags []string) ([]*ServiceInstance, error)
- func (s *Service) GetServiceURL(ctx context.Context, serviceName string, scheme string, ...) (string, error)
- func (s *Service) Health(ctx context.Context) error
- func (s *Service) ListServices(ctx context.Context) ([]string, error)
- func (s *Service) Name() string
- func (s *Service) Register(ctx context.Context, instance *ServiceInstance) error
- func (s *Service) SelectInstance(ctx context.Context, serviceName string, strategy LoadBalanceStrategy) (*ServiceInstance, error)
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
- func (s *Service) Watch(ctx context.Context, serviceName string, onChange func([]*ServiceInstance)) error
- type ServiceConfig
- type ServiceEvent
- type ServiceEventType
- type ServiceInstance
- type ServiceQuery
- type ServiceRegistration
- type WatchConfig
Constants ¶
const ( // ServiceKey is the DI key for the discovery service. ServiceKey = "discovery" // ServiceKeyLegacy is the legacy DI key for the discovery service. ServiceKeyLegacy = "discovery.Service" )
DI container keys for discovery extension services.
const ( // HealthStatusPassing indicates the service is healthy. HealthStatusPassing = backends.HealthStatusPassing // HealthStatusWarning indicates the service has warnings. HealthStatusWarning = backends.HealthStatusWarning // HealthStatusCritical indicates the service is unhealthy. HealthStatusCritical = backends.HealthStatusCritical // HealthStatusUnknown indicates the health status is unknown. HealthStatusUnknown = backends.HealthStatusUnknown )
Variables ¶
This section is empty.
Functions ¶
func NewExtension ¶
func NewExtension(opts ...ConfigOption) forge.Extension
NewExtension creates a new service discovery extension.
func NewExtensionWithConfig ¶
NewExtensionWithConfig creates a new extension with complete config.
Types ¶
type Config ¶
type Config struct {
// Enabled determines if service discovery is enabled
Enabled bool `json:"enabled" yaml:"enabled"`
// Backend specifies the service discovery backend
// Options: "consul", "etcd", "kubernetes", "eureka", "memory"
Backend string `json:"backend" yaml:"backend"`
// Service configuration for this instance
Service ServiceConfig `json:"service" yaml:"service"`
// Health check settings
HealthCheck HealthCheckConfig `json:"health_check" yaml:"health_check"`
// Watch settings
Watch WatchConfig `json:"watch" yaml:"watch"`
// Consul-specific settings
Consul ConsulConfig `json:"consul" yaml:"consul"`
// Etcd-specific settings
Etcd EtcdConfig `json:"etcd" yaml:"etcd"`
// Kubernetes-specific settings
Kubernetes KubernetesConfig `json:"kubernetes" yaml:"kubernetes"`
// Eureka-specific settings
Eureka EurekaConfig `json:"eureka" yaml:"eureka"`
// MDNS-specific settings
MDNS MDNSConfig `json:"mdns" yaml:"mdns"`
// HTTP polling-based discovery settings
HTTP HTTPConfig `json:"http" yaml:"http"`
// FARP (Forge API Gateway Registration Protocol) settings
FARP FARPConfig `json:"farp" yaml:"farp"`
}
Config holds service discovery extension configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default service discovery configuration.
type ConfigOption ¶
type ConfigOption func(*Config)
ConfigOption configures the service discovery extension.
func WithAppConfig ¶
func WithAppConfig(appConfig forge.AppConfig) ConfigOption
WithAppConfig sets the app config for auto-detecting service info This allows the extension to read Name, Version, and HTTPAddress from the app config when Service config is not fully provided.
func WithAutoDeregister ¶ added in v0.9.9
func WithAutoDeregister(enabled bool) ConfigOption
WithAutoDeregister sets whether the service is automatically deregistered on shutdown.
func WithBackend ¶
func WithBackend(backend string) ConfigOption
WithBackend sets the service discovery backend.
func WithConsul ¶
func WithConsul(address, token string) ConfigOption
WithConsul configures Consul backend.
func WithEnabled ¶
func WithEnabled(enabled bool) ConfigOption
WithEnabled sets whether service discovery is enabled.
func WithFARP ¶ added in v0.9.9
func WithFARP(farp FARPConfig) ConfigOption
WithFARP sets the full FARP configuration.
func WithFARPAutoRegister ¶ added in v0.9.9
func WithFARPAutoRegister(autoRegister bool) ConfigOption
WithFARPAutoRegister sets whether schemas are automatically registered on startup.
func WithFARPCapabilities ¶ added in v0.9.9
func WithFARPCapabilities(capabilities ...string) ConfigOption
WithFARPCapabilities sets the FARP capability tags.
func WithFARPCollapseServiceTags ¶ added in v1.6.0
func WithFARPCollapseServiceTags(collapse bool) ConfigOption
WithFARPCollapseServiceTags groups all routes under a single tag matching the service name instead of individual tags.
func WithFARPEnabled ¶ added in v0.9.9
func WithFARPEnabled(enabled bool) ConfigOption
WithFARPEnabled sets whether FARP schema registration is enabled.
func WithFARPEndpoints ¶ added in v0.9.9
func WithFARPEndpoints(endpoints FARPEndpointsConfig) ConfigOption
WithFARPEndpoints sets the FARP endpoint configuration.
func WithFARPExcludeInternalPaths ¶ added in v1.6.0
func WithFARPExcludeInternalPaths(exclude bool) ConfigOption
WithFARPExcludeInternalPaths sets whether internal framework paths are filtered from published schemas. Default is true.
func WithFARPGatewayURL ¶ added in v1.4.0
func WithFARPGatewayURL(url string) ConfigOption
WithFARPGatewayURL sets the gateway URL for push-based service registration. When set, the service will POST its registration to the gateway on startup and send deregistration on shutdown.
func WithFARPPathRules ¶ added in v1.6.0
func WithFARPPathRules(rules ...farp.PathRule) ConfigOption
WithFARPPathRules sets path include/exclude rules for filtering which API paths are published to the gateway. Supports glob wildcards.
func WithFARPSchemas ¶ added in v0.9.9
func WithFARPSchemas(schemas ...FARPSchemaConfig) ConfigOption
WithFARPSchemas sets the FARP schema configurations.
func WithFARPStrategy ¶ added in v0.9.9
func WithFARPStrategy(strategy string) ConfigOption
WithFARPStrategy sets the FARP registration strategy (push, pull, or hybrid).
func WithHTTPHealthCheck ¶
func WithHTTPHealthCheck(endpoint string, interval time.Duration) ConfigOption
WithHTTPHealthCheck sets HTTP health check.
func WithHTTPPollInterval ¶ added in v1.4.0
func WithHTTPPollInterval(d time.Duration) ConfigOption
WithHTTPPollInterval sets the HTTP backend poll interval.
func WithHTTPSeeds ¶ added in v1.4.0
func WithHTTPSeeds(seeds ...string) ConfigOption
WithHTTPSeeds configures the HTTP backend with seed URLs.
func WithHTTPTimeout ¶ added in v1.4.0
func WithHTTPTimeout(d time.Duration) ConfigOption
WithHTTPTimeout sets the HTTP backend request timeout.
func WithHealthCheck ¶
func WithHealthCheck(config HealthCheckConfig) ConfigOption
WithHealthCheck sets the health check configuration.
func WithKubernetes ¶
func WithKubernetes(namespace string, inCluster bool) ConfigOption
WithKubernetes configures Kubernetes backend.
func WithMDNSBrowseTimeout ¶ added in v0.9.9
func WithMDNSBrowseTimeout(d time.Duration) ConfigOption
WithMDNSBrowseTimeout sets the mDNS browse operation timeout.
func WithMDNSIPv6 ¶ added in v0.9.9
func WithMDNSIPv6(enabled bool) ConfigOption
WithMDNSIPv6 sets whether mDNS uses IPv6.
func WithMDNSInterface ¶ added in v0.9.9
func WithMDNSInterface(iface string) ConfigOption
WithMDNSInterface sets the network interface for mDNS operations.
func WithMDNSServiceType ¶ added in v0.9.9
func WithMDNSServiceType(serviceType string) ConfigOption
WithMDNSServiceType sets the mDNS service type for registration.
func WithMDNSServiceTypes ¶ added in v0.9.9
func WithMDNSServiceTypes(types ...string) ConfigOption
WithMDNSServiceTypes sets the mDNS service types to browse for discovery.
func WithMDNSTTL ¶ added in v0.9.9
func WithMDNSTTL(ttl uint32) ConfigOption
WithMDNSTTL sets the mDNS DNS record time-to-live.
func WithMDNSWatchInterval ¶ added in v0.9.9
func WithMDNSWatchInterval(d time.Duration) ConfigOption
WithMDNSWatchInterval sets the mDNS watch polling interval.
func WithService ¶
func WithService(service ServiceConfig) ConfigOption
WithService sets the service configuration.
func WithServiceAddress ¶
func WithServiceAddress(address string, port int) ConfigOption
WithServiceAddress sets the service address and port.
func WithServiceID ¶ added in v0.9.9
func WithServiceID(id string) ConfigOption
WithServiceID sets the unique service instance identifier.
func WithServiceMetadata ¶
func WithServiceMetadata(metadata map[string]string) ConfigOption
WithServiceMetadata sets the service metadata.
func WithServiceName ¶
func WithServiceName(name string) ConfigOption
WithServiceName sets the service name.
func WithServiceTags ¶
func WithServiceTags(tags ...string) ConfigOption
WithServiceTags sets the service tags.
func WithServiceVersion ¶ added in v0.9.9
func WithServiceVersion(version string) ConfigOption
WithServiceVersion sets the service version string.
func WithWatch ¶
func WithWatch(services []string, onChange func([]*ServiceInstance)) ConfigOption
WithWatch enables service watching.
type ConsulConfig ¶
type ConsulConfig = backends.ConsulConfig
ConsulConfig holds Consul-specific configuration.
type EtcdConfig ¶
type EtcdConfig = backends.EtcdConfig
EtcdConfig holds etcd-specific configuration.
type EurekaConfig ¶
type EurekaConfig = backends.EurekaConfig
EurekaConfig holds Eureka-specific configuration.
type Extension ¶
type Extension struct {
*forge.BaseExtension
// contains filtered or unexported fields
}
Extension implements forge.Extension for service discovery. The extension manages route registration and self-registration, while Service lifecycle is managed by Vessel.
func (*Extension) Dependencies ¶
Dependencies returns extension dependencies.
func (*Extension) Health ¶
Health checks the extension health. Service health is managed by Vessel through Service.Health().
func (*Extension) LocalServiceID ¶ added in v1.6.2
LocalServiceID returns the host process's own registered service ID, or "" when the extension hasn't started or didn't register an instance. Consumers (e.g. the dashboard discovery integration) use this to filter the host's self-registration out of cross-service polling, since memory- backed discovery surfaces the local registration alongside any peers.
func (*Extension) Run ¶ added in v1.6.0
Run executes background tasks after the app server is running. Implements forge.RunnableExtension.
func (*Extension) ServiceNode ¶ added in v1.6.0
func (e *Extension) ServiceNode() *farpdiscovery.ServiceNode
ServiceNode returns the FARP ServiceNode if active, or nil.
func (*Extension) Shutdown ¶ added in v1.6.0
Shutdown gracefully stops background tasks before the app shuts down. Implements forge.RunnableExtension.
type FARPConfig ¶
type FARPConfig struct {
// Enabled determines if FARP schema registration is enabled
Enabled bool `json:"enabled" yaml:"enabled"`
// AutoRegister automatically registers schemas on service startup
AutoRegister bool `json:"auto_register" yaml:"auto_register"`
// Strategy for schema storage: "push" (to registry), "pull" (HTTP only), "hybrid"
Strategy string `json:"strategy" yaml:"strategy"`
// Schemas to register
Schemas []FARPSchemaConfig `json:"schemas" yaml:"schemas"`
// Endpoints configuration
Endpoints FARPEndpointsConfig `json:"endpoints" yaml:"endpoints"`
// Capabilities advertised by this service
Capabilities []string `json:"capabilities" yaml:"capabilities"`
// GatewayURL is the base URL of the API gateway to push registrations to.
// When set, the service will POST its registration on startup and
// send deregistration on shutdown.
// Example: "http://localhost:7903"
GatewayURL string `json:"gateway_url" yaml:"gateway_url"`
// ExcludeInternalPaths filters out internal framework paths (/_farp/*, /_/*, /docs/*, etc.)
// from the OpenAPI/AsyncAPI schemas published to the gateway.
// Default: true
ExcludeInternalPaths *bool `json:"exclude_internal_paths,omitempty" yaml:"exclude_internal_paths,omitempty"`
// CollapseServiceTags groups all routes under a single tag matching the service name
// instead of preserving individual tags (e.g., "TwinOS" instead of "TwinOS_Agents",
// "TwinOS_Query", etc.). This is passed to the gateway's merger via the manifest.
// Default: false
CollapseServiceTags bool `json:"collapse_service_tags" yaml:"collapse_service_tags"`
// PathRules defines include/exclude rules for controlling which API paths
// are published to the gateway. Rules are evaluated in order; first match wins.
// Supports glob patterns: "*" matches one path segment, "**" matches zero or more.
// Paths not matching any rule are included by default.
//
// Example:
// PathRules: []farp.PathRule{
// {Pattern: "/internal/**", Action: farp.PathRuleExclude},
// {Pattern: "/api/users/*", Action: farp.PathRuleExclude},
// {Pattern: "/api/**", Action: farp.PathRuleInclude},
// }
PathRules []farp.PathRule `json:"path_rules,omitempty" yaml:"path_rules,omitempty"`
}
FARPConfig holds FARP (Forge API Gateway Registration Protocol) configuration.
func (*FARPConfig) ShouldExcludeInternalPaths ¶ added in v1.6.0
func (c *FARPConfig) ShouldExcludeInternalPaths() bool
ShouldExcludeInternalPaths returns whether internal paths should be filtered. Defaults to true when not explicitly set.
type FARPEndpointsConfig ¶
type FARPEndpointsConfig struct {
// Health check endpoint
Health string `json:"health" yaml:"health"`
// Metrics endpoint
Metrics string `json:"metrics,omitempty" yaml:"metrics,omitempty"`
// OpenAPI spec endpoint
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
// AsyncAPI spec endpoint
AsyncAPI string `json:"asyncapi,omitempty" yaml:"asyncapi,omitempty"`
// gRPC reflection enabled
GRPCReflection bool `json:"grpc_reflection,omitempty" yaml:"grpc_reflection,omitempty"`
// GraphQL endpoint
GraphQL string `json:"graphql,omitempty" yaml:"graphql,omitempty"`
}
FARPEndpointsConfig configures service endpoints.
type FARPLocationConfig ¶
type FARPLocationConfig struct {
// Type: "http", "registry", "inline"
Type string `json:"type" yaml:"type"`
// URL for HTTP location type
URL string `json:"url,omitempty" yaml:"url,omitempty"`
// RegistryPath for registry location type
RegistryPath string `json:"registry_path,omitempty" yaml:"registry_path,omitempty"`
// Headers for HTTP authentication
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
}
FARPLocationConfig configures where the schema is located.
type FARPSchemaConfig ¶
type FARPSchemaConfig struct {
// Type of schema: "openapi", "asyncapi", "grpc", "graphql"
Type string `json:"type" yaml:"type"`
// SpecVersion is the schema specification version (e.g., "3.1.0" for OpenAPI)
SpecVersion string `json:"spec_version" yaml:"spec_version"`
// Location configuration
Location FARPLocationConfig `json:"location" yaml:"location"`
// ContentType is the schema content type
ContentType string `json:"content_type" yaml:"content_type"`
}
FARPSchemaConfig configures a single schema to register.
type HTTPConfig ¶ added in v1.4.0
type HTTPConfig = backends.HTTPConfig
HTTPConfig holds HTTP polling-based discovery configuration. Polls known service URLs at their /_farp/discovery endpoints.
type HealthCheckConfig ¶
type HealthCheckConfig struct {
// Enabled determines if health checks are enabled
Enabled bool `json:"enabled" yaml:"enabled"`
// Interval is how often to perform health checks
Interval time.Duration `json:"interval" yaml:"interval"`
// Timeout is the health check timeout
Timeout time.Duration `json:"timeout" yaml:"timeout"`
// DeregisterCriticalServiceAfter is when to deregister unhealthy services
DeregisterCriticalServiceAfter time.Duration `json:"deregister_critical_service_after" yaml:"deregister_critical_service_after"`
// HTTP health check endpoint (if using HTTP)
HTTP string `json:"http" yaml:"http"`
// TCP health check address (if using TCP)
TCP string `json:"tcp" yaml:"tcp"`
// gRPC health check address (if using gRPC)
GRPC string `json:"grpc" yaml:"grpc"`
}
HealthCheckConfig holds health check configuration.
type HealthStatus ¶
type HealthStatus = backends.HealthStatus
HealthStatus represents service health status.
type KubernetesConfig ¶
type KubernetesConfig = backends.KubernetesConfig
KubernetesConfig holds Kubernetes-specific configuration.
type LoadBalanceStrategy ¶
type LoadBalanceStrategy string
LoadBalanceStrategy defines load balancing strategies.
const ( // LoadBalanceRoundRobin uses round-robin selection. LoadBalanceRoundRobin LoadBalanceStrategy = "round_robin" // LoadBalanceRandom uses random selection. LoadBalanceRandom LoadBalanceStrategy = "random" // LoadBalanceLeastConnections uses least connections selection. LoadBalanceLeastConnections LoadBalanceStrategy = "least_connections" // LoadBalanceWeightedRoundRobin uses weighted round-robin. LoadBalanceWeightedRoundRobin LoadBalanceStrategy = "weighted_round_robin" )
type MDNSConfig ¶
type MDNSConfig = backends.MDNSConfig
MDNSConfig holds mDNS/DNS-SD-specific configuration Works natively on macOS (Bonjour), Linux (Avahi), and Windows (DNS-SD).
type SchemaPublisher ¶
type SchemaPublisher struct {
// contains filtered or unexported fields
}
SchemaPublisher handles FARP schema registration.
func NewSchemaPublisher ¶
func NewSchemaPublisher(config FARPConfig, app forge.App) *SchemaPublisher
NewSchemaPublisher creates a new schema publisher.
func (*SchemaPublisher) Close ¶
func (p *SchemaPublisher) Close() error
Close closes the schema publisher.
func (*SchemaPublisher) GetManifest ¶
func (p *SchemaPublisher) GetManifest(ctx context.Context, instanceID string) (*farp.SchemaManifest, error)
GetManifest retrieves the manifest for an instance.
func (*SchemaPublisher) GetMetadataForDiscovery ¶
func (p *SchemaPublisher) GetMetadataForDiscovery(baseURL string) map[string]string
GetMetadataForDiscovery returns metadata that should be added to service discovery This allows mDNS/Bonjour and other backends to advertise FARP endpoints in TXT records.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides high-level service discovery operations. It implements di.Service for lifecycle management.
func NewService ¶
NewService creates a new service discovery service.
func (*Service) Backend ¶
Backend returns the underlying discovery backend. This allows the extension to access the backend for self-registration.
func (*Service) Deregister ¶
Deregister deregisters a service instance.
func (*Service) DiscoverHealthy ¶
func (s *Service) DiscoverHealthy(ctx context.Context, serviceName string) ([]*ServiceInstance, error)
DiscoverHealthy discovers only healthy service instances.
func (*Service) DiscoverWithTags ¶
func (s *Service) DiscoverWithTags(ctx context.Context, serviceName string, tags []string) ([]*ServiceInstance, error)
DiscoverWithTags discovers service instances by name and tags.
func (*Service) GetServiceURL ¶
func (s *Service) GetServiceURL(ctx context.Context, serviceName string, scheme string, strategy LoadBalanceStrategy) (string, error)
GetServiceURL gets a service URL using load balancing.
func (*Service) ListServices ¶
ListServices lists all registered services.
func (*Service) Register ¶
func (s *Service) Register(ctx context.Context, instance *ServiceInstance) error
Register registers a service instance.
func (*Service) SelectInstance ¶
func (s *Service) SelectInstance(ctx context.Context, serviceName string, strategy LoadBalanceStrategy) (*ServiceInstance, error)
SelectInstance selects a single service instance using load balancing strategy.
type ServiceConfig ¶
type ServiceConfig struct {
// Name is the service name
Name string `json:"name" yaml:"name"`
// ID is the unique service instance ID (auto-generated if empty)
ID string `json:"id" yaml:"id"`
// Version is the service version
Version string `json:"version" yaml:"version"`
// Address is the service address
Address string `json:"address" yaml:"address"`
// Port is the service port
Port int `json:"port" yaml:"port"`
// Tags are service tags for filtering
Tags []string `json:"tags" yaml:"tags"`
// Metadata is arbitrary service metadata
Metadata map[string]string `json:"metadata" yaml:"metadata"`
// EnableAutoDeregister enables automatic deregistration on shutdown
EnableAutoDeregister bool `json:"enable_auto_deregister" yaml:"enable_auto_deregister"`
}
ServiceConfig holds service registration configuration.
type ServiceEvent ¶
type ServiceEvent struct {
// Type is the event type
Type ServiceEventType
// Service is the service instance
Service *ServiceInstance
// Timestamp is when the event occurred
Timestamp int64
}
ServiceEvent represents a service change event.
type ServiceEventType ¶
type ServiceEventType string
ServiceEventType represents types of service events.
const ( // ServiceEventRegistered indicates a service was registered. ServiceEventRegistered ServiceEventType = "registered" // ServiceEventDeregistered indicates a service was deregistered. ServiceEventDeregistered ServiceEventType = "deregistered" // ServiceEventHealthChanged indicates service health changed. ServiceEventHealthChanged ServiceEventType = "health_changed" // ServiceEventMetadataChanged indicates service metadata changed. ServiceEventMetadataChanged ServiceEventType = "metadata_changed" )
type ServiceInstance ¶
type ServiceInstance = backends.ServiceInstance
ServiceInstance represents a registered service instance.
type ServiceQuery ¶
type ServiceQuery struct {
// Name is the service name to query
Name string
// Tags are tags to filter by
Tags []string
// OnlyHealthy returns only healthy instances
OnlyHealthy bool
// LoadBalanceStrategy is the load balancing strategy
LoadBalanceStrategy LoadBalanceStrategy
}
ServiceQuery represents a service discovery query.
type ServiceRegistration ¶
type ServiceRegistration struct {
// Service is the service configuration
Service ServiceConfig
// HealthCheck is the health check configuration
HealthCheck HealthCheckConfig
}
ServiceRegistration represents a service registration request.
type WatchConfig ¶
type WatchConfig struct {
// Enabled determines if service watching is enabled
Enabled bool `json:"enabled" yaml:"enabled"`
// Services are service names to watch for changes
Services []string `json:"services" yaml:"services"`
// Tags are tags to filter services
Tags []string `json:"tags" yaml:"tags"`
// OnChange is called when watched services change
// This is set programmatically, not via config
OnChange func(services []*ServiceInstance)
}
WatchConfig holds service watch configuration.