Documentation
¶
Index ¶
- Constants
- func NewExtension(opts ...ConfigOption) forge.Extension
- func NewExtensionWithConfig(config Config) forge.Extension
- type Backend
- type Config
- type 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
- 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 `yaml:"enabled" json:"enabled"`
// Backend specifies the service discovery backend
// Options: "consul", "etcd", "kubernetes", "eureka", "memory"
Backend string `yaml:"backend" json:"backend"`
// Service configuration for this instance
Service ServiceConfig `yaml:"service" json:"service"`
// Health check settings
HealthCheck HealthCheckConfig `yaml:"health_check" json:"health_check"`
// Watch settings
Watch WatchConfig `yaml:"watch" json:"watch"`
// Consul-specific settings
Consul ConsulConfig `yaml:"consul" json:"consul"`
// Etcd-specific settings
Etcd EtcdConfig `yaml:"etcd" json:"etcd"`
// Kubernetes-specific settings
Kubernetes KubernetesConfig `yaml:"kubernetes" json:"kubernetes"`
// Eureka-specific settings
Eureka EurekaConfig `yaml:"eureka" json:"eureka"`
// MDNS-specific settings
MDNS MDNSConfig `yaml:"mdns" json:"mdns"`
// FARP (Forge API Gateway Registration Protocol) settings
FARP FARPConfig `yaml:"farp" json:"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 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 `yaml:"enabled" json:"enabled"`
// AutoRegister automatically registers schemas on service startup
AutoRegister bool `yaml:"auto_register" json:"auto_register"`
// Strategy for schema storage: "push" (to registry), "pull" (HTTP only), "hybrid"
Strategy string `yaml:"strategy" json:"strategy"`
// Schemas to register
Schemas []FARPSchemaConfig `yaml:"schemas" json:"schemas"`
// Endpoints configuration
Endpoints FARPEndpointsConfig `yaml:"endpoints" json:"endpoints"`
// Capabilities advertised by this service
Capabilities []string `yaml:"capabilities" json:"capabilities"`
}
FARPConfig holds FARP (Forge API Gateway Registration Protocol) configuration
type FARPEndpointsConfig ¶
type FARPEndpointsConfig struct {
// Health check endpoint
Health string `yaml:"health" json:"health"`
// Metrics endpoint
Metrics string `yaml:"metrics,omitempty" json:"metrics,omitempty"`
// OpenAPI spec endpoint
OpenAPI string `yaml:"openapi,omitempty" json:"openapi,omitempty"`
// AsyncAPI spec endpoint
AsyncAPI string `yaml:"asyncapi,omitempty" json:"asyncapi,omitempty"`
// gRPC reflection enabled
GRPCReflection bool `yaml:"grpc_reflection,omitempty" json:"grpc_reflection,omitempty"`
// GraphQL endpoint
GraphQL string `yaml:"graphql,omitempty" json:"graphql,omitempty"`
}
FARPEndpointsConfig configures service endpoints
type FARPLocationConfig ¶
type FARPLocationConfig struct {
// Type: "http", "registry", "inline"
Type string `yaml:"type" json:"type"`
// URL for HTTP location type
URL string `yaml:"url,omitempty" json:"url,omitempty"`
// RegistryPath for registry location type
RegistryPath string `yaml:"registry_path,omitempty" json:"registry_path,omitempty"`
// Headers for HTTP authentication
Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
}
FARPLocationConfig configures where the schema is located
type FARPSchemaConfig ¶
type FARPSchemaConfig struct {
// Type of schema: "openapi", "asyncapi", "grpc", "graphql"
Type string `yaml:"type" json:"type"`
// SpecVersion is the schema specification version (e.g., "3.1.0" for OpenAPI)
SpecVersion string `yaml:"spec_version" json:"spec_version"`
// Location configuration
Location FARPLocationConfig `yaml:"location" json:"location"`
// ContentType is the schema content type
ContentType string `yaml:"content_type" json:"content_type"`
}
FARPSchemaConfig configures a single schema to register
type HealthCheckConfig ¶
type HealthCheckConfig struct {
// Enabled determines if health checks are enabled
Enabled bool `yaml:"enabled" json:"enabled"`
// Interval is how often to perform health checks
Interval time.Duration `yaml:"interval" json:"interval"`
// Timeout is the health check timeout
Timeout time.Duration `yaml:"timeout" json:"timeout"`
// DeregisterCriticalServiceAfter is when to deregister unhealthy services
DeregisterCriticalServiceAfter time.Duration `yaml:"deregister_critical_service_after" json:"deregister_critical_service_after"`
// HTTP health check endpoint (if using HTTP)
HTTP string `yaml:"http" json:"http"`
// TCP health check address (if using TCP)
TCP string `yaml:"tcp" json:"tcp"`
// gRPC health check address (if using gRPC)
GRPC string `yaml:"grpc" json:"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
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 `yaml:"name" json:"name"`
// ID is the unique service instance ID (auto-generated if empty)
ID string `yaml:"id" json:"id"`
// Version is the service version
Version string `yaml:"version" json:"version"`
// Address is the service address
Address string `yaml:"address" json:"address"`
// Port is the service port
Port int `yaml:"port" json:"port"`
// Tags are service tags for filtering
Tags []string `yaml:"tags" json:"tags"`
// Metadata is arbitrary service metadata
Metadata map[string]string `yaml:"metadata" json:"metadata"`
// EnableAutoDeregister enables automatic deregistration on shutdown
EnableAutoDeregister bool `yaml:"enable_auto_deregister" json:"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 `yaml:"enabled" json:"enabled"`
// Services are service names to watch for changes
Services []string `yaml:"services" json:"services"`
// Tags are tags to filter services
Tags []string `yaml:"tags" json:"tags"`
// OnChange is called when watched services change
// This is set programmatically, not via config
OnChange func(services []*ServiceInstance)
}
WatchConfig holds service watch configuration