Documentation ¶
Index ¶
- Constants
- func Client() etcd.Client
- func KAPI() etcd.KeysAPI
- func Subscribe(service string) etcd.Watcher
- func SubscribeDown(service string) (<-chan string, <-chan *etcd.Error)
- func SubscribeNew(service string) (<-chan *Host, <-chan *etcd.Error)
- type Credentials
- type GetHostResponse
- type GetServiceResponse
- func (q *GetServiceResponse) All() (Hosts, error)
- func (q *GetServiceResponse) Err() error
- func (q *GetServiceResponse) First() HostResponse
- func (q *GetServiceResponse) One() HostResponse
- func (q *GetServiceResponse) Service() (*Service, error)
- func (q *GetServiceResponse) URL(scheme, path string) (string, error)
- type Host
- type HostResponse
- type Hosts
- type Ports
- type Registration
- type RegistrationWrapper
- type Service
- type ServiceResponse
Constants ¶
const ( // HEARTBEAT_DURATION time in second between two registration. The host will // be deleted if etcd didn't received any new registration in those 5 seocnds HEARTBEAT_DURATION = 5 )
Variables ¶
This section is empty.
Functions ¶
func Client ¶
Client will generate a valid etcd client from the following environment variables:
- ETCD_HOSTS: a list of etcd hosts comma separated
- ETCD_HOST: a single etcd host
- ETCD_CACERT: The ca certificate
- ETCD_TLS_CERT: The client tls cert
- ETCD_TLS_KEY: The client tls key
- ETCD_TLS_INMEMORY: Is the tls configuration filename or raw certificates
func SubscribeDown ¶
SubscribeDown return a channel that will notice you everytime a host loose his etcd registration
Types ¶
type Credentials ¶
Credentials store service credentials
type GetHostResponse ¶
type GetHostResponse struct {
// contains filtered or unexported fields
}
GetHostResponse is the HostResponse Implementation of the HostResponse interface used by the the Service methods. This only provide the error wrapping logic, all the actaul logic for these method are done by the Host struct.
func (*GetHostResponse) Err ¶
func (q *GetHostResponse) Err() error
Err will return an error if an error happened on any previous steps.
func (*GetHostResponse) Host ¶
func (q *GetHostResponse) Host() (*Host, error)
Host will return the host represented by this error.
func (*GetHostResponse) PrivateURL ¶
func (q *GetHostResponse) PrivateURL(scheme, path string) (string, error)
PrivateURL will return the private URL of this host
type GetServiceResponse ¶
type GetServiceResponse struct {
// contains filtered or unexported fields
}
GetServiceResponse is the implementation of the ServiceResponse interface used by the Get method This only provide the error wrapping logic, all the actual logic for thsese mêthod are done by the Service struct.
func (*GetServiceResponse) All ¶
func (q *GetServiceResponse) All() (Hosts, error)
All will return a slice of all the hosts registred to the service
func (*GetServiceResponse) Err ¶
func (q *GetServiceResponse) Err() error
Err wil return an error if an error happend when you've called tre Get method, or nil if no error were detected.
func (*GetServiceResponse) First ¶
func (q *GetServiceResponse) First() HostResponse
First will return the first host registred to the service If the ServiceResponse is errored, the errors will be passed to the HostResponse
func (*GetServiceResponse) One ¶
func (q *GetServiceResponse) One() HostResponse
One will return a host choosen randomly in all the hosts of the service If the ServiceResponse is errored, the errors will be passed to the HostResponse
func (*GetServiceResponse) Service ¶
func (q *GetServiceResponse) Service() (*Service, error)
Service will return the service returned by the Get method. If the service was not found, no error will be return but the service will only contains a Name field.
type Host ¶
type Host struct { // Hostname must be a publicly available IP/FQDN if the service is public or a private IP/FQDN id the service is private. Hostname string `json:"name"` // Name of the service which this host store. This will be overwritten by the Register Function Name string `json:"service_name"` // Ports is the ports accessible on a public network if the service is Public or the ports accessible on a private network if the service is private Ports Ports `json:"ports"` // User name used to authenticate to this service. The Register function can override this at any time if the service is public User string `json:"user,omitempty"` // Password used to authenticate to this service. The Register function can override this at any time if the service is public Password string `json:"password,omitempty"` // Public is set to true if the service is public Public bool `json:"public,omitempty"` // PrivateHostname is the private IP/FQDN used to communicate with this service on the private network // This will defaults to Hostname if empty PrivateHostname string `json:"private_hostname,omitempty"` // PrivatePorts is the private ports used to communicate with this service on the private network. // This will defaults to Ports if empty PrivatePorts Ports `json:"private_ports,omitempty"` // Critical will be set to true is the service is critical Critical bool `json:"critical,omitempty"` // UUID is the service UUID, this must have the following pattern: uuid-PrivateHostname UUID string `json:"uuid,omitempty"` }
Host store all the host informations. This is also used to store the host in the etcd services directory.
func (*Host) PrivateURL ¶
PrivateURL will provide a valid url to contact this service on the Private network this method will fallback to the URL method if the host does not provide any PrivateURL
type HostResponse ¶
type HostResponse interface { Err() error Host() (*Host, error) URL(scheme, path string) (string, error) PrivateURL(scheme, path string) (string, error) }
HostResponse is the interface used to provide a single host response. This interface provide a standard API used fot method chaining like:
Get("my-service").First().Url()
To provide such API errores need to be stored and sent at the last moment. To do so each "final" methods (like URL or Host) will check if the Response is errored before continuing to their own logic.
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 Registration ¶
type Registration struct {
// contains filtered or unexported fields
}
Registration is the RegistrationWrapper implementation used by the Register method
func NewRegistration ¶
func NewRegistration(ctx context.Context, uuid string, cred chan Credentials) *Registration
NewRegistration initialize the Registration struct
func Register ¶
func Register(ctx context.Context, service string, host Host) *Registration
Register a host with a service name and a host description. The last chan is a stop method. If something is written on this channel, any goroutines launch by this method will stop.
This service will launch two go routines. The first one will maintain the registration every 5 seconds and the second one will check if the service credentials don't change and notify otherwise
func (*Registration) Credentials ¶
func (w *Registration) Credentials() (Credentials, error)
Credentials return the service credentials or an error if the service is not registred yet
func (*Registration) Ready ¶
func (w *Registration) Ready() bool
Ready is a non blocking method that return true if the service is registred to the etcd service false otherwise
func (*Registration) WaitRegistration ¶
func (w *Registration) WaitRegistration()
WaitRegistration wait for the first registration to happen, meaning that the service is succesfulled registred to the etcd service
type RegistrationWrapper ¶
type RegistrationWrapper interface { Ready() bool // Ready return strue if the service registred yet? This method should no be blocking WaitRegistration() // WaitRegistration wait for the first registration Credentials() (Credentials, error) // Credentials return the current credentials or an error if the service is not registred yet UUID() string // UUID return the host UUID }
RegistrationWrapper wreap the uuid and the credential channel to provide a more user friendly API for the Register Method
type Service ¶
type Service struct { Name string `json:"name"` // Name of the service Critical bool `json:"critical"` // Is the service critical to the infrastructure health? Hostname string `json:"hostname,omitempty"` // The service private hostname User string `json:"user,omitempty"` // The service username Password string `json:"password,omitempty"` // The service password Ports Ports `json:"ports,omitempty"` // The service private ports Public bool `json:"public,omitempty"` // Is the service public? }
Service store all the informatiosn about a service. This is also used to marshal services present in the /services_infos/ directory.
type ServiceResponse ¶
type ServiceResponse interface { // Err is the method used to check if the Response is errored. Err() error // Service return the Service struct representing the requested service Service() (*Service, error) // One return a host of the service choosen randomly One() HostResponse // First return the first host of the serice First() HostResponse // All return all the hosts registred for this service All() (Hosts, error) // URL returns a valid url for this service URL(scheme, path string) (string, error) }
ServiceResponse is the interface used to provide a response to the service.Get() Method. This interface provide a standard API used for method chaining like:
url, err := Get("my-service").First().URL()
To provide such API, go errors need to be stored and sent at the last moment. To do so, each "final" method (like Url or All), will check if the Response is errored, before continuing to their own logic.
func Get ¶
func Get(service string) ServiceResponse
Get a service by its name. This method does not directly return the Service, but a ServiceResponse. This permit method chaining like:
url, err := Get("my-service").First().URL()
If there was an error during the acquisition of the service, this error will be stored in the ServiceResponse. Final methods will check for this error before doing actual logic. If the service is not found, we won't render an error, but will return a service with minimal informations. This is done to provide maximal backwerd compatibility since older versions does not register themself to the "/services_infos" directory.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package servicemock is a generated GoMock package.
|
Package servicemock is a generated GoMock package. |