eureka

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: MIT Imports: 22 Imported by: 85

Documentation

Index

Constants

View Source
const (
	UP       = "UP"
	DOWN     = "DOWN"
	STARTING = "STARTING"
)
View Source
const (
	ErrCodeEurekaNotReachable = 501
	ErrCodeInstanceNotFound   = 502
)

Variables

View Source
var (
	ErrRequestCancelled = errors.New("sending request is cancelled")
)

Errors introduced by handling requests

Functions

func DefaultCheckRetry

func DefaultCheckRetry(cluster *Cluster, numReqs int, lastResp http.Response,
	err error) error

DefaultCheckRetry defines the retrying behaviour for bad HTTP requests If we have retried 2 * machine number, stop retrying. If status code is InternalServerError, sleep for 200ms.

func GetLogger

func GetLogger() *log.Logger

func SetLogger

func SetLogger(loggerLog *log.Logger)

Types

type Application

type Application struct {
	Name      string         `xml:"name"`
	Instances []InstanceInfo `xml:"instance"`
}

type Applications

type Applications struct {
	VersionsDelta int           `xml:"versions__delta"`
	AppsHashcode  string        `xml:"apps__hashcode"`
	Applications  []Application `xml:"application,omitempty"`
}

type Client

type Client struct {
	Config  Config   `json:"config"`
	Cluster *Cluster `json:"cluster"`

	// CheckRetry can be used to control the policy for failed requests
	// and modify the cluster if needed.
	// The client calls it before sending requests again, and
	// stops retrying if CheckRetry returns some error. The cases that
	// this function needs to handle include no response and unexpected
	// http status code of response.
	// If CheckRetry is nil, client will call the default one
	// `DefaultCheckRetry`.
	// Argument cluster is the eureka.Cluster object that these requests have been made on.
	// Argument numReqs is the number of http.Requests that have been made so far.
	// Argument lastResp is the http.Responses from the last request.
	// Argument err is the reason of the failure.
	CheckRetry func(cluster *Cluster, numReqs int,
		lastResp http.Response, err error) error
	// contains filtered or unexported fields
}

func NewClient

func NewClient(machines []string) *Client

NewClient create a basic client that is configured to be used with the given machine list.

func NewClientFromFile

func NewClientFromFile(fpath string) (*Client, error)

NewClientFromFile creates a client from a given file path. The given file is expected to use the JSON format.

func NewClientFromReader

func NewClientFromReader(reader io.Reader) (*Client, error)

NewClientFromReader creates a Client configured from a given reader. The configuration is expected to use the JSON format.

func NewTLSClient

func NewTLSClient(machines []string, cert string, key string, caCerts []string) (*Client, error)

NewTLSClient create a basic client with TLS configuration

func (*Client) AddRootCA

func (c *Client) AddRootCA(caCert string) error

AddRootCA adds a root CA cert for the eureka client

func (*Client) Delete

func (c *Client) Delete(endpoint string) (*RawResponse, error)

delete issues a DELETE request

func (*Client) Get

func (c *Client) Get(endpoint string) (*RawResponse, error)

get issues a GET request

func (*Client) GetApplication

func (c *Client) GetApplication(appId string) (*Application, error)

func (*Client) GetApplications

func (c *Client) GetApplications() (*Applications, error)

func (*Client) GetCluster

func (c *Client) GetCluster() []string

func (*Client) GetInstance

func (c *Client) GetInstance(appId, instanceId string) (*InstanceInfo, error)

func (*Client) GetSVIP

func (c *Client) GetSVIP(svipId string) (*Applications, error)

func (*Client) GetVIP

func (c *Client) GetVIP(vipId string) (*Applications, error)

func (*Client) MarshalJSON

func (c *Client) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaller interface as defined by the standard JSON package.

func (*Client) Post

func (c *Client) Post(endpoint string, body []byte) (*RawResponse, error)

post issues a POST request

func (*Client) Put

func (c *Client) Put(endpoint string, body []byte) (*RawResponse, error)

put issues a PUT request

func (*Client) RegisterInstance

func (c *Client) RegisterInstance(appId string, instanceInfo *InstanceInfo) error

func (*Client) SendHeartbeat

func (c *Client) SendHeartbeat(appId, instanceId string) error

func (*Client) SendRequest

func (c *Client) SendRequest(rr *RawRequest) (*RawResponse, error)

func (*Client) SetCluster

func (c *Client) SetCluster(machines []string) bool

SetCluster updates cluster information using the given machine list.

func (*Client) SetDialTimeout

func (c *Client) SetDialTimeout(d time.Duration)

Sets the DialTimeout value

func (*Client) SetTransport

func (c *Client) SetTransport(tr *http.Transport)

Override the Client's HTTP Transport object

func (*Client) SyncCluster

func (c *Client) SyncCluster() bool

SyncCluster updates the cluster information using the internal machine list.

func (*Client) UnmarshalJSON

func (c *Client) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaller interface as defined by the standard JSON package.

func (*Client) UnregisterInstance

func (c *Client) UnregisterInstance(appId, instanceId string) error

type Cluster

type Cluster struct {
	Leader   string   `json:"leader"`
	Machines []string `json:"machines"`
}

func NewCluster

func NewCluster(machines []string) *Cluster

type Config

type Config struct {
	CertFile    string        `json:"certFile"`
	KeyFile     string        `json:"keyFile"`
	CaCertFile  []string      `json:"caCertFiles"`
	DialTimeout time.Duration `json:"timeout"`
	Consistency string        `json:"consistency"`
}

type DataCenterInfo

type DataCenterInfo struct {
	Name     string              `xml:"name" json:"name"`
	Class    string              `xml:"class,attr" json:"@class"`
	Metadata *DataCenterMetadata `xml:"metadata,omitempty" json:"metadata,omitempty"`
}

type DataCenterMetadata

type DataCenterMetadata struct {
	AmiLaunchIndex   string `xml:"ami-launch-index,omitempty" json:"ami-launch-index,omitempty"`
	LocalHostname    string `xml:"local-hostname,omitempty" json:"local-hostname,omitempty"`
	AvailabilityZone string `xml:"availability-zone,omitempty" json:"availability-zone,omitempty"`
	InstanceId       string `xml:"instance-id,omitempty" json:"instance-id,omitempty"`
	PublicIpv4       string `xml:"public-ipv4,omitempty" json:"public-ipv4,omitempty"`
	PublicHostname   string `xml:"public-hostname,omitempty" json:"public-hostname,omitempty"`
	AmiManifestPath  string `xml:"ami-manifest-path,omitempty" json:"ami-manifest-path,omitempty"`
	LocalIpv4        string `xml:"local-ipv4,omitempty" json:"local-ipv4,omitempty"`
	Hostname         string `xml:"hostname,omitempty" json:"hostname,omitempty"`
	AmiId            string `xml:"ami-id,omitempty" json:"ami-id,omitempty"`
	InstanceType     string `xml:"instance-type,omitempty" json:"instance-type,omitempty"`
}

type EurekaError

type EurekaError struct {
	ErrorCode int    `json:"errorCode"`
	Message   string `json:"message"`
	Cause     string `json:"cause,omitempty"`
	Index     uint64 `json:"index"`
}

func (EurekaError) Error

func (e EurekaError) Error() string

type Instance

type Instance struct {
	Instance *InstanceInfo `xml:"instance" json:"instance"`
}

type InstanceInfo

type InstanceInfo struct {
	HostName                      string          `xml:"hostName" json:"hostName"`
	HomePageUrl                   string          `xml:"homePageUrl,omitempty" json:"homePageUrl,omitempty"`
	StatusPageUrl                 string          `xml:"statusPageUrl" json:"statusPageUrl"`
	HealthCheckUrl                string          `xml:"healthCheckUrl,omitempty" json:"healthCheckUrl,omitempty"`
	App                           string          `xml:"app" json:"app"`
	IpAddr                        string          `xml:"ipAddr" json:"ipAddr"`
	VipAddress                    string          `xml:"vipAddress" json:"vipAddress"`
	SecureVipAddress              string          `xml:"secureVipAddress,omitempty" json:"secureVipAddress,omitempty"`
	Status                        string          `xml:"status" json:"status"`
	Port                          *Port           `xml:"port,omitempty" json:"port,omitempty"`
	SecurePort                    *Port           `xml:"securePort,omitempty" json:"securePort,omitempty"`
	DataCenterInfo                *DataCenterInfo `xml:"dataCenterInfo" json:"dataCenterInfo"`
	LeaseInfo                     *LeaseInfo      `xml:"leaseInfo,omitempty" json:"leaseInfo,omitempty"`
	Metadata                      *MetaData       `xml:"metadata,omitempty" json:"metadata,omitempty"`
	IsCoordinatingDiscoveryServer bool            `xml:"isCoordinatingDiscoveryServer,omitempty" json:"isCoordinatingDiscoveryServer,omitempty"`
	LastUpdatedTimestamp          int             `xml:"lastUpdatedTimestamp,omitempty" json:"lastUpdatedTimestamp,omitempty"`
	LastDirtyTimestamp            int             `xml:"lastDirtyTimestamp,omitempty" json:"lastDirtyTimestamp,omitempty"`
	ActionType                    string          `xml:"actionType,omitempty" json:"actionType,omitempty"`
	Overriddenstatus              string          `xml:"overriddenstatus,omitempty" json:"overriddenstatus,omitempty"`
	CountryId                     int             `xml:"countryId,omitempty" json:"countryId,omitempty"`
	InstanceID                    string          `xml:"instanceId,omitempty" json:"instanceId,omitempty"`
}

func NewInstanceInfo

func NewInstanceInfo(hostName, app, ip string, port int, ttl uint, isSsl bool) *InstanceInfo

type LeaseInfo

type LeaseInfo struct {
	EvictionDurationInSecs uint `xml:"evictionDurationInSecs,omitempty" json:"evictionDurationInSecs,omitempty"`
	RenewalIntervalInSecs  int  `xml:"renewalIntervalInSecs,omitempty" json:"renewalIntervalInSecs,omitempty"`
	DurationInSecs         int  `xml:"durationInSecs,omitempty" json:"durationInSecs,omitempty"`
	RegistrationTimestamp  int  `xml:"registrationTimestamp,omitempty" json:"registrationTimestamp,omitempty"`
	LastRenewalTimestamp   int  `xml:"lastRenewalTimestamp,omitempty" json:"lastRenewalTimestamp,omitempty"`
	EvictionTimestamp      int  `xml:"evictionTimestamp,omitempty" json:"evictionTimestamp,omitempty"`
	ServiceUpTimestamp     int  `xml:"serviceUpTimestamp,omitempty" json:"serviceUpTimestamp,omitempty"`
}

type MetaData

type MetaData struct {
	Map   map[string]string
	Class string
}

func (*MetaData) MarshalJSON

func (s *MetaData) MarshalJSON() ([]byte, error)

func (*MetaData) MarshalXML

func (s *MetaData) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*MetaData) UnmarshalJSON

func (s *MetaData) UnmarshalJSON(data []byte) error

func (*MetaData) UnmarshalXML

func (s *MetaData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Port

type Port struct {
	Port    int  `xml:",chardata" json:"$"`
	Enabled bool `xml:"enabled,attr" json:"@enabled"`
}

type RawRequest

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

func NewRawRequest

func NewRawRequest(method, relativePath string, body []byte, cancel <-chan bool) *RawRequest

type RawResponse

type RawResponse struct {
	StatusCode int
	Body       []byte
	Header     http.Header
}

type Vraw

type Vraw struct {
	Content []byte `xml:",innerxml"`
	Class   string `xml:"class,attr" json:"@class"`
}

Jump to

Keyboard shortcuts

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