Documentation
¶
Index ¶
- Variables
- func GenerateInstanceID(serviceName string) string
- type Check
- type Host
- type Ports
- type Registry
- type Service
- type ServiceID
- type ServiceInfo
- type ServicePrefix
- type SyncAtomicValue
- type SyncInt64Value
- type SyncUInt64Value
- type SyncValue
- type ValueClient
- type ValueSetter
- type ValueSetterFunc
- type Valuer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when no service addresses are found. ErrNotFound = errors.New("no service addresses found") // ErrNotReady is returned when the service is not ready. ErrNotReady = errors.New("service is not ready") )
Functions ¶
func GenerateInstanceID ¶
GenerateInstanceID generates a psuedo-random service instance identifier, using a service name. Suffixed by dash and number
Types ¶
type Check ¶
type Check struct { ID string TTL time.Duration // Health checks can be of different types and applicable in only some drivers. HTTP struct { URL string Method string Headers map[string][]string } }
Check represents a health check for a service.
type Host ¶
type Host struct { Hostname string `json:"hostname"` Ports Ports `json:"ports"` User string `json:"user,omitempty"` Password string `json:"password,omitempty"` }
Host represents a host in the cloud registry.
type Ports ¶
Ports is a representation of the ports exposed by a host or a service. The key is the protocol name and the value is the port used for this protocol. Typical usage is:
Ports{ "http":"80", "https": "443", }
type Registry ¶
type Registry interface { io.Closer ValueClient // Register registers a service in the cloud registry. Register(ctx context.Context, service *Service) error // Deregister deregisters a service from the cloud registry. Deregister(ctx context.Context, id *ServiceID) error // Discover discovers a service in the cloud registry. Discover(ctx context.Context, prefix *ServicePrefix, TTL time.Duration) ([]*ServiceInfo, error) // HealthCheck checks the health of a service in the cloud registry. HealthCheck(ctx context.Context, id *ServiceID, TTL time.Duration) error }
Registry is the interface that wraps the basic methods to interact with the cloud registry.
type Service ¶
type Service struct { Name string Namespace string Partition string InstanceID string Hostname string Port int Public []Host Private []Host Tags []string Meta map[string]string Check Check }
Service represents a service in the cloud registry.
func (*Service) Prefix ¶
func (service *Service) Prefix() *ServicePrefix
Prefix returns the service prefix of the service.
type ServiceID ¶
func (*ServiceID) Prefix ¶
func (id *ServiceID) Prefix() *ServicePrefix
Prefix returns the service prefix of the service ID.
type ServiceInfo ¶
type ServiceInfo struct { Name string `json:"name"` Namespace string `json:"namespace,omitempty"` Partition string `json:"partition,omitempty"` InstanceID string `json:"instance_id"` Hostname string `json:"hostname"` Port int `json:"port"` Public []Host `json:"public,omitempty"` Private []Host `json:"private,omitempty"` Tags []string `json:"tags,omitempty"` Meta map[string]string `json:"meta,omitempty"` RawInfo any `json:"raw_info,omitempty"` LastUpdate time.Time `json:"last_update"` }
ServiceInfo represents a service in the cloud registry.
type ServicePrefix ¶
func (*ServicePrefix) String ¶
func (prefix *ServicePrefix) String() string
String returns the string representation of the service prefix.
type SyncAtomicValue ¶
type SyncAtomicValue[T syncValue[V], V any] struct { // contains filtered or unexported fields }
SyncAtomicValue is a thread-safe value holder.
func NewSyncAtomicValue ¶
func NewSyncAtomicValue[T syncValue[V], V any](vl T) *SyncAtomicValue[T, V]
NewSyncAtomicValue creates a new SyncAtomicValue with the given value.
func (*SyncAtomicValue[T, V]) SetValue ¶
func (v *SyncAtomicValue[T, V]) SetValue(_ string, val any) error
SetValue sets the value to the given value.
func (*SyncAtomicValue[T, V]) Value ¶
func (v *SyncAtomicValue[T, V]) Value() V
Value returns the value.
type SyncInt64Value ¶
type SyncInt64Value struct {
// contains filtered or unexported fields
}
SyncInt64Value is a thread-safe int64 value holder.
func NewSyncInt64Value ¶
func NewSyncInt64Value(val int64) *SyncInt64Value
NewSyncInt64Value creates a new SyncInt64Value with the given value.
type SyncUInt64Value ¶
type SyncUInt64Value struct {
// contains filtered or unexported fields
}
SyncUInt64Value is a thread-safe uint64 value holder.
func NewSyncUInt64Value ¶
func NewSyncUInt64Value(val uint64) *SyncUInt64Value
NewSyncUInt64Value creates a new SyncUInt64Value with the given value.
type SyncValue ¶
type SyncValue[T any] struct { // contains filtered or unexported fields }
SyncValue is a thread-safe value holder.
func NewSyncValue ¶
NewSyncValue creates a new SyncValue with the given value.
type ValueClient ¶
type ValueClient interface { // Values returns a ValueClient to interact with the cloud registry. Values(ctx context.Context, prefix ...string) ValueClient // Value returns a value from the cloud registry. Value(ctx context.Context, name string) (string, error) // SetValue sets a value in the cloud registry. SetValue(ctx context.Context, name, value string) error // SubscribeValue subscribes to a value in the cloud registry. SubscribeValue(ctx context.Context, name string, val ValueSetter) error // SubscribeValueWithPrefix subscribes to a value in the cloud registry. SubscribeValueWithPrefix(ctx context.Context, prefix string, val ValueSetter) error }
ValueClient is the interface that wraps the basic methods to interact with the cloud registry.
type ValueSetter ¶
ValueSetter is the interface that wraps the basic methods to set a value.
type ValueSetterFunc ¶
ValueSetterFunc is an adapter to allow the use of ordinary functions as ValueSetter.
type Valuer ¶
type Valuer[T any] interface { ValueSetter Value() T }
Valuer is the interface that wraps the basic methods to get a value.