client

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

type Client struct {
	// contains filtered or unexported fields
}

Client implements the ServiceDiscovery and ServiceRegistry interfaces using Amalgam8 Registry REST API.

func New

func New(config Config) (*Client, error)

New constructs a new Client using the given configuration.

func (*Client) Debug added in v1.0.0

func (client *Client) Debug(debug bool)

Debug is used to set the debugging flag.

func (*Client) Deregister added in v1.0.0

func (client *Client) Deregister(id string) error

Deregister removes a registered service instance, identified by the given ID, from the registry.

func (*Client) ListInstances added in v1.0.0

func (client *Client) ListInstances() ([]*api.ServiceInstance, error)

ListInstances queries for the list of service instances currently registered.

func (*Client) ListInstancesWithFilter added in v1.0.0

func (client *Client) ListInstancesWithFilter(filter InstanceFilter) ([]*api.ServiceInstance, error)

ListInstancesWithFilter queries for the list of service instances currently registered that satisfy the given filter.

func (*Client) ListServiceInstances added in v1.0.0

func (client *Client) ListServiceInstances(serviceName string) ([]*api.ServiceInstance, error)

ListServiceInstances queries for the list of service instances currently registered for the given service.

func (*Client) ListServices added in v1.0.0

func (client *Client) ListServices() ([]string, error)

ListServices queries for the list of services for which instances are currently registered.

func (*Client) Register added in v1.0.0

func (client *Client) Register(instance *api.ServiceInstance) (*api.ServiceInstance, error)

Register adds a service instance, described by the given ServiceInstance structure, to the registry.

func (*Client) Renew added in v1.0.0

func (client *Client) Renew(id string) error

Renew sends a heartbeat for the service instance identified by the given ID.

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 Error

type Error struct {
	Code      ErrorCode
	Message   string
	Cause     error
	RequestID string
}

Error represents an actual error occurred which using the client.

func (Error) Error

func (err Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents an error condition which might occur when using the client.

const (
	ErrorCodeUndefined ErrorCode = iota

	ErrorCodeUnknownInstance

	ErrorCodeConnectionFailure

	ErrorCodeServiceUnavailable
	ErrorCodeInternalServerError

	ErrorCodeUnauthorized
	ErrorCodeInvalidConfiguration
	ErrorCodeInternalClientError
)

Enumerate valid ErrorCode values.

func (ErrorCode) String

func (code ErrorCode) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL