Documentation
¶
Index ¶
- Constants
- Variables
- func NewCommonException(format string, args ...interface{}) error
- func NewIOException(e error, args ...interface{}) error
- func NewJSONException(e error, args ...interface{}) error
- type AddressPool
- type CallOption
- type CallOptions
- type Client
- func (c *Client) AddSchemas(microServiceID, schemaName, schemaInfo string) error
- func (c *Client) BatchFindInstances(consumerID string, keys []*discovery.FindService, opts ...CallOption) (*discovery.BatchFindInstancesResponse, error)
- func (c *Client) Close() error
- func (c *Client) FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
- func (c *Client) GetAllApplications(opts ...CallOption) ([]string, error)
- func (c *Client) GetAllMicroServices(opts ...CallOption) ([]*discovery.MicroService, error)
- func (c *Client) GetAllResources(resource string, opts ...CallOption) ([]*discovery.ServiceDetail, error)
- func (c *Client) GetDefaultHeaders() http.Header
- func (c *Client) GetMicroService(microServiceID string, opts ...CallOption) (*discovery.MicroService, error)
- func (c *Client) GetMicroServiceID(appID, microServiceName, version, env string, opts ...CallOption) (string, error)
- func (c *Client) GetMicroServiceInstances(consumerID, providerID string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
- func (c *Client) GetProviders(consumer string, opts ...CallOption) (*MicroServiceProvideResponse, error)
- func (c *Client) GetSchema(microServiceID, schemaName string, opts ...CallOption) ([]byte, error)
- func (c *Client) Health() ([]*discovery.MicroServiceInstance, error)
- func (c *Client) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
- func (c *Client) RegisterMicroServiceInstance(microServiceInstance *discovery.MicroServiceInstance) (string, error)
- func (c *Client) RegisterService(microService *discovery.MicroService) (string, error)
- func (c *Client) ResetRevision()
- func (c *Client) SyncEndpoints() error
- func (c *Client) UnregisterMicroService(microServiceID string) (bool, error)
- func (c *Client) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error)
- func (c *Client) UpdateMicroServiceInstanceProperties(microServiceID, microServiceInstanceID string, ...) (bool, error)
- func (c *Client) UpdateMicroServiceInstanceStatus(microServiceID, microServiceInstanceID, status string) (bool, error)
- func (c *Client) UpdateMicroServiceProperties(microServiceID string, microService *discovery.MicroService) (bool, error)
- func (c *Client) WatchMicroService(microServiceID string, callback func(*MicroServiceInstanceChangedEvent)) error
- type MicroServiceInstanceChangedEvent
- type MicroServiceProvideResponse
- type Next
- type Options
- type RegistryConfig
- type RegistryException
- type URLBuilder
- type URLParameter
Constants ¶
const ( MicroservicePath = "/microservices" InstancePath = "/instances" BatchInstancePath = "/instances/action" SchemaPath = "/schemas" HeartbeatPath = "/heartbeat" ExistencePath = "/existence" WatchPath = "/watcher" StatusPath = "/status" DependencyPath = "/dependencies" PropertiesPath = "/properties" HeaderContentType = "Content-Type" HeaderUserAgent = "User-Agent" DefaultAddr = "127.0.0.1:30100" AppsPath = "/apps" DefaultRetryTimeout = 500 * time.Millisecond HeaderRevision = "X-Resource-Revision" EnvProjectID = "CSE_PROJECT_ID" // EnvCheckSCIInterval sc instance health check interval in second EnvCheckSCIInterval = "CHASSIS_SC_HEALTH_CHECK_INTERVAL" )
Define constants for the client
const ( //EventCreate is a constant of type string EventCreate string = "CREATE" //EventUpdate is a constant of type string EventUpdate string = "UPDATE" //EventDelete is a constant of type string EventDelete string = "DELETE" //EventError is a constant of type string EventError string = "ERROR" //MicorserviceUp is a constant of type string MicorserviceUp string = "UP" //MicroserviceDown is a constant of type string MicroserviceDown string = "DOWN" //MSInstanceUP is a constant of type string MSInstanceUP string = "UP" //MSIinstanceDown is a constant of type string MSIinstanceDown string = "DOWN" //CheckByHeartbeat is a constant of type string CheckByHeartbeat string = "push" //DefaultLeaseRenewalInterval is a constant of type int which declares default lease renewal time DefaultLeaseRenewalInterval = 30 //APIPath is a constant of type string APIPath = "/registry/v3" )
Variables ¶
var ( MSAPIPath = "" GovernAPIPATH = "" TenantHeader = "X-Domain-Name" )
Define variables for the client
var ( //ErrNotModified means instance is not changed ErrNotModified = errors.New("instance is not changed since last query") //ErrMicroServiceExists means service is registered ErrMicroServiceExists = errors.New("micro-service already exists") // ErrMicroServiceNotExists means service is not exists ErrMicroServiceNotExists = errors.New("micro-service does not exist") //ErrEmptyCriteria means you gave an empty list of criteria ErrEmptyCriteria = errors.New("batch find criteria is empty") )
var ErrNoneAvailable = errors.New("no available")
ErrNoneAvailable create a new error with Message No available
Functions ¶
func NewCommonException ¶
NewCommonException creates a generic exception
func NewIOException ¶
NewIOException create and IO exception
func NewJSONException ¶
NewJSONException creates a JSON exception
Types ¶
type AddressPool ¶
type AddressPool struct {
// contains filtered or unexported fields
}
AddressPool registry address pool
func (*AddressPool) GetAvailableAddress ¶
func (p *AddressPool) GetAvailableAddress() string
GetAvailableAddress Get an available address from pool by roundrobin
func (*AddressPool) Monitor ¶
func (p *AddressPool) Monitor()
Monitor monitor each service center network connectivity
func (*AddressPool) SetAddress ¶
func (p *AddressPool) SetAddress(addresses []string)
SetAddress set addresses to pool
type CallOption ¶
type CallOption func(*CallOptions)
CallOption is receiver for options and chang the attribute of it
func WithGlobal ¶
func WithGlobal() CallOption
WithGlobal query resources include other aggregated SC
func WithoutRevision ¶
func WithoutRevision() CallOption
WithoutRevision ignore current revision number
type CallOptions ¶
CallOptions is options when you call a API
type Client ¶ added in v0.6.0
type Client struct { Config *RegistryConfig // contains filtered or unexported fields }
Client communicate to Service-Center
func (*Client) AddSchemas ¶ added in v0.6.0
AddSchemas adds a schema contents to the services registered in service-center
func (*Client) BatchFindInstances ¶ added in v0.6.0
func (c *Client) BatchFindInstances(consumerID string, keys []*discovery.FindService, opts ...CallOption) (*discovery.BatchFindInstancesResponse, error)
BatchFindInstances fetch instances based on service name, env, app and version finally it return instances grouped by service name
func (*Client) FindMicroServiceInstances ¶ added in v0.6.0
func (c *Client) FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
FindMicroServiceInstances find microservice instance using consumerID, appID, name and version rule
func (*Client) GetAllApplications ¶ added in v0.6.0
func (c *Client) GetAllApplications(opts ...CallOption) ([]string, error)
GetAllApplications returns the list of all the applications which is registered in governance-center
func (*Client) GetAllMicroServices ¶ added in v0.6.0
func (c *Client) GetAllMicroServices(opts ...CallOption) ([]*discovery.MicroService, error)
GetAllMicroServices gets list of all the microservices registered with Service-Center
func (*Client) GetAllResources ¶ added in v0.6.0
func (c *Client) GetAllResources(resource string, opts ...CallOption) ([]*discovery.ServiceDetail, error)
GetAllResources retruns all the list of services, instances, providers, consumers in the service-center
func (*Client) GetDefaultHeaders ¶ added in v0.6.0
GetDefaultHeaders gets the default headers for each request to be made to Service-Center
func (*Client) GetMicroService ¶ added in v0.6.0
func (c *Client) GetMicroService(microServiceID string, opts ...CallOption) (*discovery.MicroService, error)
GetMicroService returns the microservices by ID
func (*Client) GetMicroServiceID ¶ added in v0.6.0
func (c *Client) GetMicroServiceID(appID, microServiceName, version, env string, opts ...CallOption) (string, error)
GetMicroServiceID gets the microserviceid by appID, serviceName and version
func (*Client) GetMicroServiceInstances ¶ added in v0.6.0
func (c *Client) GetMicroServiceInstances(consumerID, providerID string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
GetMicroServiceInstances queries the service-center with provider and consumer ID and returns the microservice-instance
func (*Client) GetProviders ¶ added in v0.6.0
func (c *Client) GetProviders(consumer string, opts ...CallOption) (*MicroServiceProvideResponse, error)
GetProviders gets a list of provider for a particular consumer
func (*Client) GetSchema ¶ added in v0.6.0
func (c *Client) GetSchema(microServiceID, schemaName string, opts ...CallOption) ([]byte, error)
GetSchema gets Schema list for the microservice from service-center
func (*Client) Health ¶ added in v0.6.0
func (c *Client) Health() ([]*discovery.MicroServiceInstance, error)
Health returns the list of all the endpoints of SC with their status
func (*Client) Heartbeat ¶ added in v0.6.0
Heartbeat sends the heartbeat to service-senter for particular service-instance
func (*Client) RegisterMicroServiceInstance ¶ added in v0.6.0
func (c *Client) RegisterMicroServiceInstance(microServiceInstance *discovery.MicroServiceInstance) (string, error)
RegisterMicroServiceInstance registers the microservice instance to Servive-Center
func (*Client) RegisterService ¶ added in v0.6.0
func (c *Client) RegisterService(microService *discovery.MicroService) (string, error)
RegisterService registers the micro-services to Service-Center
func (*Client) ResetRevision ¶ added in v0.6.0
func (c *Client) ResetRevision()
ResetRevision reset the revision to 0
func (*Client) SyncEndpoints ¶ added in v0.6.0
SyncEndpoints gets the endpoints of service-center in the cluster you only need to call this function, if your service center is not behind a load balancing service like ELB,nginx etc
func (*Client) UnregisterMicroService ¶ added in v0.6.0
UnregisterMicroService un-registers the microservice from the service-center
func (*Client) UnregisterMicroServiceInstance ¶ added in v0.6.0
func (c *Client) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error)
UnregisterMicroServiceInstance un-registers the microservice instance from the service-center
func (*Client) UpdateMicroServiceInstanceProperties ¶ added in v0.6.0
func (c *Client) UpdateMicroServiceInstanceProperties(microServiceID, microServiceInstanceID string, microServiceInstance *discovery.MicroServiceInstance) (bool, error)
UpdateMicroServiceInstanceProperties updates the microserviceinstance prooperties in the service-center
func (*Client) UpdateMicroServiceInstanceStatus ¶ added in v0.6.0
func (c *Client) UpdateMicroServiceInstanceStatus(microServiceID, microServiceInstanceID, status string) (bool, error)
UpdateMicroServiceInstanceStatus updates the microservicve instance status in service-center
func (*Client) UpdateMicroServiceProperties ¶ added in v0.6.0
func (c *Client) UpdateMicroServiceProperties(microServiceID string, microService *discovery.MicroService) (bool, error)
UpdateMicroServiceProperties updates the microservice properties in the servive-center
func (*Client) WatchMicroService ¶ added in v0.6.0
func (c *Client) WatchMicroService(microServiceID string, callback func(*MicroServiceInstanceChangedEvent)) error
WatchMicroService creates a web socket connection to service-center to keep a watch on the providers for a micro-service
type MicroServiceInstanceChangedEvent ¶
type MicroServiceInstanceChangedEvent struct { Action string `protobuf:"bytes,2,opt,name=action" json:"action,omitempty"` Key *discovery.MicroServiceKey `protobuf:"bytes,3,opt,name=key" json:"key,omitempty"` Instance *discovery.MicroServiceInstance `protobuf:"bytes,4,opt,name=instance" json:"instance,omitempty"` }
MicroServiceInstanceChangedEvent is a struct to store the Changed event information
type MicroServiceProvideResponse ¶
type MicroServiceProvideResponse struct {
Services []*discovery.MicroService `json:"providers,omitempty"`
}
MicroServiceProvideResponse is a struct with provider information
type Options ¶
type Options struct { Endpoints []string EnableSSL bool Timeout time.Duration TLSConfig *tls.Config // Other options can be stored in a context Context context.Context Compressed bool Verbose bool Version string }
Options is the list of dynamic parameter's which can be passed to the Client while creating a new client
type RegistryConfig ¶
type RegistryConfig struct {
SSL bool
}
RegistryConfig is a structure to store registry configurations like address of cc, ssl configurations and tenant name
type RegistryException ¶
RegistryException structure contains message and error information for the exception caused by service-center
func (*RegistryException) Error ¶
func (e *RegistryException) Error() string
Error gets the Error message from the Error
type URLBuilder ¶
type URLBuilder struct { Protocol string Host string Path string URLParameters []URLParameter CallOptions *CallOptions }
URLBuilder is the string builder to build request url
func (*URLBuilder) String ¶
func (b *URLBuilder) String() string
String is the method to return url string
type URLParameter ¶
URLParameter maintains the list of parameters to be added in URL