Discovery

Functions

Public API reference for the Discovery extension

Extension Entry Points

FunctionDescription
NewExtension(opts ...ConfigOption) forge.ExtensionCreate the discovery extension with functional options
NewExtensionWithConfig(config Config) forge.ExtensionCreate the extension with a complete config
DefaultConfig() ConfigReturns the default configuration

DI Helpers

FunctionDescription
GetService(c forge.Container) (*Service, error)Resolve the discovery service from the container
MustGetService(c forge.Container) *ServiceSame but panics on error
GetServiceFromApp(app forge.App) (*Service, error)Resolve from an app instance
MustGetServiceFromApp(app forge.App) *ServiceSame but panics on error

Service -- Registration

MethodDescription
Register(ctx, instance) errorRegister a service instance
Deregister(ctx, instance) errorRemove a service instance

Service -- Discovery

MethodDescription
Discover(ctx, serviceName) ([]*ServiceInstance, error)Find all instances of a service
DiscoverWithTags(ctx, serviceName, tags) ([]*ServiceInstance, error)Find instances matching tags
DiscoverHealthy(ctx, serviceName) ([]*ServiceInstance, error)Find only healthy instances
SelectInstance(ctx, serviceName) (*ServiceInstance, error)Pick one instance (load balanced)
GetServiceURL(ctx, serviceName) (string, error)Get the URL of a healthy instance
ListServices(ctx) ([]string, error)List all registered service names

Service -- Watching

MethodDescription
Watch(ctx, serviceName, callback) errorSubscribe to service change events

Service -- Backend Access

MethodDescription
Backend() BackendAccess the underlying backend directly
Health(ctx) errorCheck discovery service health

FARP Endpoints

When FARP is enabled, the following HTTP endpoints are registered:

EndpointDescription
GET /_farp/manifestFARP manifest describing the service's API schemas
GET /_farp/discoveryDiscovery information for other services

How is this guide?

On this page