Documentation
¶
Index ¶
Constants ¶
const ( FieldID = "id" FieldServiceName = "service_name" FieldEndpoint = "endpoint" FieldStatus = "status" FieldTags = "tags" FieldMetadata = "metadata" FieldTTL = "ttl" FieldLastHeartbeat = "last_heartbeat" )
Enumerates available values for InstanceField.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client unifies the Registry and Discovery interfaces under a single interface.
type Config ¶
type Config struct {
// URL of the registry server.
URL string
// AuthToken is the bearer token to be used for authentication with the registry.
// If left empty, no authentication is used.
AuthToken string
// HTTPClient can be used to customize the underlying HTTP client behavior,
// such as enabling TLS, setting timeouts, etc.
// If left nil, a default HTTP client will be used.
HTTPClient *http.Client
}
Config stores the configurable attributes of the client.
type Discovery ¶
type Discovery interface {
// ListServices queries the registry for the list of services for which instances are currently registered.
ListServices() ([]string, error)
// ListInstances queries the registry for the list of service instances currently registered.
// The given InstanceFilter can be used to filter the returned instances as well as the fields returned for each.
ListInstances(filter InstanceFilter) ([]*ServiceInstance, error)
// ListServiceInstances queries the registry for the list of service instances with status 'UP' currently
// registered for the given service.
ListServiceInstances(serviceName string) ([]*ServiceInstance, error)
}
Discovery defines the interface used by clients for discovering service instances from the registry.
type Error ¶
Error represents an actual error occurred which using the client.
type ErrorCode ¶
type ErrorCode int
ErrorCode represents an error condition which might occur when using the client.
type InstanceFilter ¶
type InstanceFilter struct {
// ServiceName is used to filter service instances based on their service name.
// When set to a non-empty string, registered service instances will be returned
// only if their service name matches the specified service name.
ServiceName string
// Status is used to filter service instances based on their status.
// When set to a non-empty string, registered service instances will be returned
// only if their status matches the specified status.
// When left empty, only instances with status "UP" will be returned.
// When set to "ALL", all instances will be returned, regardless of their status.
Status string
// Tags is used to filter service instances based on their tags.
// When set to a non-empty array, registered service instances will be returned
// only if they are tagged with each of the specified tags.
Tags []string
// Fields is used to filter the fields returned for each service instance.
// When set to a non-empty array, returned service instances will have their corresponding fields set,
// while other fields will remain at their zero-value.
// When set to an empty or nil array, returned service instances will have all of their fields set.
Fields []string
}
InstanceFilter is used to filter service instances returned from lookup calls.
The zero-value indicates to use the registry's default filtering, which includes all service instances with status 'UP', and include all fields in the response.
type Registry ¶
type Registry interface {
// Register adds a service instance, described by the given ServiceInstance structure, to the registry.
// The returned ServiceInstance is mostly similar to the given one, but includes additional
// attributes set by the registry server, such as the service instance ID and TTL.
Register(instance *ServiceInstance) (*ServiceInstance, error)
// Deregister removes a registered service instance, identified by the given ID, from the registry.
Deregister(id string) error
// Renew sends a heartbeat for the service instance identified by the given ID.
Renew(id string) error
}
Registry defines the interface used by clients for registering service instances with the registry.
type ServiceEndpoint ¶
type ServiceEndpoint struct {
// Type is the endpoint's type. Valid values are "http", "tcp", or "user".
Type string `json:"type"`
// Value is the endpoint's value according to its type,
// e.g. "172.135.10.1:8080" or "http://myapp.ng.bluemix.net/api/v1".
Value string `json:"value"`
}
ServiceEndpoint describes a network endpoint of service instance.
func NewCustomEndpoint ¶
func NewCustomEndpoint(endpoint string) ServiceEndpoint
NewCustomEndpoint creates a new network endpoint of a custom type. The value may be any arbitrary description of a network endpoint which makes sense in the context of the application.
func NewHTTPEndpoint ¶
func NewHTTPEndpoint(httpURL url.URL) ServiceEndpoint
NewHTTPEndpoint creates a new HTTP(S) network endpoint with the specified URL. The specified URL is assumed to have an "http" or "https" scheme.
func NewTCPEndpoint ¶
func NewTCPEndpoint(host string, port int) ServiceEndpoint
NewTCPEndpoint creates a new TCP network endpoint with the specified host and optional port.
type ServiceInstance ¶
type ServiceInstance struct {
// ID is the unique ID assigned to this service instance by Amalgam8 Service Registry.
// This field is ignored for registration, and is mandatory for discovery.
ID string `json:"id,omitempty"`
// ServiceName is the name of the service being provided by this service instance.
// This field is mandatory both for registration and discovery.
ServiceName string `json:"service_name"`
// Endpoint is the network endpoint of this service instance.
// This field is mandatory both for registration and discovery.
Endpoint ServiceEndpoint `json:"endpoint"`
// Status is a string representing the status of the service instance.
// Valid values are "STARTING", "UP", or "OUT_OF_SERVICE".
// This field is optional both for registration and discovery.
Status string `json:"status,omitempty"`
// Tags is a set of arbitrary tags attached to this service instance.
// This field is optional both for registration and discovery.
Tags []string `json:"tags,omitempty"`
// Metadata is a marshaled JSON value associated with this service instance, in encoded-form.
// Any arbitrary JSON value is valid, including numbers, strings, arrays and objects.
// This field is optional both for registration and discovery.
Metadata json.RawMessage `json:"metadata,omitempty"`
// TTL is the time-to-live associated with this service instance, specified in seconds.
// This field is optional for registration, and is mandatory for discovery.
TTL int `json:"ttl,omitempty"`
// LastHeartbeat is the timestamp in which heartbeat has been last received for this service instance.
// This field is ignored for registration, and is mandatory for discovery.
LastHeartbeat time.Time `json:"last_heartbeat,omitempty"`
}
ServiceInstance holds information about a service instance registered with Amalgam8 Service Registry.
It is used both as an input to registration calls, as well as the output of discovery calls. Depending on the context, some of the fields may be mandatory, optional, or ignored.
Source Files
¶
- client.go
- endpoint.go
- errors.go
- filter.go
- instance.go