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 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 WithHTTPHealthCheck(endpoint string, interval time.Duration) ConfigOption
- func WithHealthCheck(config HealthCheckConfig) ConfigOption
- func WithKubernetes(namespace string, inCluster bool) ConfigOption
- func WithMDNS(domain string) ConfigOption
- func WithService(service ServiceConfig) ConfigOption
- func WithServiceAddress(address string, port int) ConfigOption
- func WithServiceMetadata(metadata map[string]string) ConfigOption
- func WithServiceName(name string) ConfigOption
- func WithServiceTags(tags ...string) ConfigOption
- func WithWatch(services []string, onChange func([]*ServiceInstance)) ConfigOption
- type ConsulConfig
- type EtcdConfig
- type EurekaConfig
- type Extension
- type FARPConfig
- type FARPEndpointsConfig
- type FARPLocationConfig
- type FARPSchemaConfig
- 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) 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) Register(ctx context.Context, instance *ServiceInstance) error
- func (s *Service) SelectInstance(ctx context.Context, serviceName string, strategy LoadBalanceStrategy) (*ServiceInstance, 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 ( // 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"`
// 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 ¶ added in v0.5.0
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 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 WithHTTPHealthCheck ¶
func WithHTTPHealthCheck(endpoint string, interval time.Duration) ConfigOption
WithHTTPHealthCheck sets HTTP health check.
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 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 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 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.
func (*Extension) Dependencies ¶
Dependencies returns extension dependencies.
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"`
}
FARPConfig holds FARP (Forge API Gateway Registration Protocol) configuration.
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 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 ¶ added in v0.5.0
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.
func NewService ¶
NewService creates a new service discovery service.
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.