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 MicroServiceInstanceChangedEvent
- type MicroServiceProvideResponse
- type Next
- type Options
- type RegistryClient
- func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo string) error
- func (c *RegistryClient) BatchFindInstances(consumerID string, keys []*discovery.FindService, opts ...CallOption) (*discovery.BatchFindInstancesResponse, error)
- func (c *RegistryClient) Close() error
- func (c *RegistryClient) FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
- func (c *RegistryClient) GetAllApplications(opts ...CallOption) ([]string, error)
- func (c *RegistryClient) GetAllMicroServices(opts ...CallOption) ([]*discovery.MicroService, error)
- func (c *RegistryClient) GetAllResources(resource string, opts ...CallOption) ([]*discovery.ServiceDetail, error)
- func (c *RegistryClient) GetDefaultHeaders() http.Header
- func (c *RegistryClient) GetMicroService(microServiceID string, opts ...CallOption) (*discovery.MicroService, error)
- func (c *RegistryClient) GetMicroServiceID(appID, microServiceName, version, env string, opts ...CallOption) (string, error)
- func (c *RegistryClient) GetMicroServiceInstances(consumerID, providerID string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
- func (c *RegistryClient) GetProviders(consumer string, opts ...CallOption) (*MicroServiceProvideResponse, error)
- func (c *RegistryClient) GetSchema(microServiceID, schemaName string, opts ...CallOption) ([]byte, error)
- func (c *RegistryClient) Health() ([]*discovery.MicroServiceInstance, error)
- func (c *RegistryClient) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
- func (c *RegistryClient) RegisterMicroServiceInstance(microServiceInstance *discovery.MicroServiceInstance) (string, error)
- func (c *RegistryClient) RegisterService(microService *discovery.MicroService) (string, error)
- func (c *RegistryClient) ResetRevision()
- func (c *RegistryClient) SyncEndpoints() error
- func (c *RegistryClient) UnregisterMicroService(microServiceID string) (bool, error)
- func (c *RegistryClient) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error)
- func (c *RegistryClient) UpdateMicroServiceInstanceProperties(microServiceID, microServiceInstanceID string, ...) (bool, error)
- func (c *RegistryClient) UpdateMicroServiceInstanceStatus(microServiceID, microServiceInstanceID, status string) (bool, error)
- func (c *RegistryClient) UpdateMicroServiceProperties(microServiceID string, microService *discovery.MicroService) (bool, error)
- func (c *RegistryClient) WatchMicroService(microServiceID string, callback func(*MicroServiceInstanceChangedEvent)) error
- 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 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 { Addrs []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 RegistryClient while creating a new client
type RegistryClient ¶
type RegistryClient struct { Config *RegistryConfig // contains filtered or unexported fields }
RegistryClient is a structure for the client to communicate to Service-Center
func NewClient ¶
func NewClient(opt Options) (*RegistryClient, error)
NewClient initializes the Registry Client
func (*RegistryClient) AddSchemas ¶
func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo string) error
AddSchemas adds a schema contents to the services registered in service-center
func (*RegistryClient) BatchFindInstances ¶
func (c *RegistryClient) 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 (*RegistryClient) Close ¶
func (c *RegistryClient) Close() error
Close closes the connection with Service-Center
func (*RegistryClient) FindMicroServiceInstances ¶
func (c *RegistryClient) FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...CallOption) ([]*discovery.MicroServiceInstance, error)
FindMicroServiceInstances find microservice instance using consumerID, appID, name and version rule
func (*RegistryClient) GetAllApplications ¶
func (c *RegistryClient) GetAllApplications(opts ...CallOption) ([]string, error)
GetAllApplications returns the list of all the applications which is registered in governance-center
func (*RegistryClient) GetAllMicroServices ¶
func (c *RegistryClient) GetAllMicroServices(opts ...CallOption) ([]*discovery.MicroService, error)
GetAllMicroServices gets list of all the microservices registered with Service-Center
func (*RegistryClient) GetAllResources ¶
func (c *RegistryClient) GetAllResources(resource string, opts ...CallOption) ([]*discovery.ServiceDetail, error)
GetAllResources retruns all the list of services, instances, providers, consumers in the service-center
func (*RegistryClient) GetDefaultHeaders ¶
func (c *RegistryClient) GetDefaultHeaders() http.Header
GetDefaultHeaders gets the default headers for each request to be made to Service-Center
func (*RegistryClient) GetMicroService ¶
func (c *RegistryClient) GetMicroService(microServiceID string, opts ...CallOption) (*discovery.MicroService, error)
GetMicroService returns the microservices by ID
func (*RegistryClient) GetMicroServiceID ¶
func (c *RegistryClient) GetMicroServiceID(appID, microServiceName, version, env string, opts ...CallOption) (string, error)
GetMicroServiceID gets the microserviceid by appID, serviceName and version
func (*RegistryClient) GetMicroServiceInstances ¶
func (c *RegistryClient) 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 (*RegistryClient) GetProviders ¶
func (c *RegistryClient) GetProviders(consumer string, opts ...CallOption) (*MicroServiceProvideResponse, error)
GetProviders gets a list of provider for a particular consumer
func (*RegistryClient) GetSchema ¶
func (c *RegistryClient) GetSchema(microServiceID, schemaName string, opts ...CallOption) ([]byte, error)
GetSchema gets Schema list for the microservice from service-center
func (*RegistryClient) Health ¶
func (c *RegistryClient) Health() ([]*discovery.MicroServiceInstance, error)
Health returns the list of all the endpoints of SC with their status
func (*RegistryClient) Heartbeat ¶
func (c *RegistryClient) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
Heartbeat sends the heartbeat to service-senter for particular service-instance
func (*RegistryClient) RegisterMicroServiceInstance ¶
func (c *RegistryClient) RegisterMicroServiceInstance(microServiceInstance *discovery.MicroServiceInstance) (string, error)
RegisterMicroServiceInstance registers the microservice instance to Servive-Center
func (*RegistryClient) RegisterService ¶
func (c *RegistryClient) RegisterService(microService *discovery.MicroService) (string, error)
RegisterService registers the micro-services to Service-Center
func (*RegistryClient) ResetRevision ¶
func (c *RegistryClient) ResetRevision()
ResetRevision reset the revision to 0
func (*RegistryClient) SyncEndpoints ¶
func (c *RegistryClient) SyncEndpoints() error
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 (*RegistryClient) UnregisterMicroService ¶
func (c *RegistryClient) UnregisterMicroService(microServiceID string) (bool, error)
UnregisterMicroService un-registers the microservice from the service-center
func (*RegistryClient) UnregisterMicroServiceInstance ¶
func (c *RegistryClient) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error)
UnregisterMicroServiceInstance un-registers the microservice instance from the service-center
func (*RegistryClient) UpdateMicroServiceInstanceProperties ¶
func (c *RegistryClient) UpdateMicroServiceInstanceProperties(microServiceID, microServiceInstanceID string, microServiceInstance *discovery.MicroServiceInstance) (bool, error)
UpdateMicroServiceInstanceProperties updates the microserviceinstance prooperties in the service-center
func (*RegistryClient) UpdateMicroServiceInstanceStatus ¶
func (c *RegistryClient) UpdateMicroServiceInstanceStatus(microServiceID, microServiceInstanceID, status string) (bool, error)
UpdateMicroServiceInstanceStatus updates the microservicve instance status in service-center
func (*RegistryClient) UpdateMicroServiceProperties ¶
func (c *RegistryClient) UpdateMicroServiceProperties(microServiceID string, microService *discovery.MicroService) (bool, error)
UpdateMicroServiceProperties updates the microservice properties in the servive-center
func (*RegistryClient) WatchMicroService ¶
func (c *RegistryClient) 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 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