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
- func RegroupInstances(keys []*proto.FindService, response proto.BatchFindInstancesResponse) map[string][]*proto.MicroServiceInstance
- type AppsResponse
- type CallOption
- type CallOptions
- type DataCenterInfo
- type DependencyMicroService
- type ExistenceIDResponse
- type Framework
- type GetServicesInfoResponse
- type HealthCheck
- type MicroServiceDependency
- type MicroServiceInstanceChangedEvent
- type MicroServiceInstanceKey
- type MicroServiceInstanceRequest
- type MicroServiceInstancesResponse
- type MicroServiceKey
- type MicroServiceProvideresponse
- type MicroServiceRequest
- type MircroServiceDependencyRequest
- type Next
- type Options
- type RegistryClient
- func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest) error
- func (c *RegistryClient) AddSchemas(microServiceID, schemaName, schemaInfo string) error
- func (c *RegistryClient) BatchFindInstances(consumerID string, keys []*proto.FindService, opts ...CallOption) (map[string][]*proto.MicroServiceInstance, error)
- func (c *RegistryClient) Close() error
- func (c *RegistryClient) FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...CallOption) ([]*proto.MicroServiceInstance, error)
- func (c *RegistryClient) GetAllApplications(opts ...CallOption) ([]string, error)
- func (c *RegistryClient) GetAllMicroServices(opts ...CallOption) ([]*proto.MicroService, error)
- func (c *RegistryClient) GetAllResources(resource string, opts ...CallOption) ([]*ServiceDetail, error)
- func (c *RegistryClient) GetDefaultHeaders() http.Header
- func (c *RegistryClient) GetMicroService(microServiceID string, opts ...CallOption) (*proto.MicroService, error)
- func (c *RegistryClient) GetMicroServiceID(appID, microServiceName, version, env string, opts ...CallOption) (string, error)
- func (c *RegistryClient) GetMicroServiceInstances(consumerID, providerID string, opts ...CallOption) ([]*proto.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) HTTPDo(method string, rawURL string, headers http.Header, body []byte) (resp *http.Response, err error)
- func (c *RegistryClient) Health() ([]*proto.MicroServiceInstance, error)
- func (c *RegistryClient) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
- func (c *RegistryClient) Initialize(opt Options) (err error)
- func (c *RegistryClient) RegisterMicroServiceInstance(microServiceInstance *proto.MicroServiceInstance) (string, error)
- func (c *RegistryClient) RegisterService(microService *proto.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 *proto.MicroService) (bool, error)
- func (c *RegistryClient) WatchMicroService(microServiceID string, callback func(*MicroServiceInstanceChangedEvent)) error
- type RegistryConfig
- type RegistryException
- type ServiceDetail
- type ServicePath
- 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" )
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 = "" TenantHeader = "X-Domain-Name" GovernAPIPATH = "" )
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
func RegroupInstances ¶
func RegroupInstances(keys []*proto.FindService, response proto.BatchFindInstancesResponse) map[string][]*proto.MicroServiceInstance
RegroupInstances organize raw data to better format
Types ¶
type AppsResponse ¶
type AppsResponse struct {
AppIds []string `json:"appIds,omitempty"`
}
AppsResponse is a struct with list of app ID's
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 DataCenterInfo ¶
type DataCenterInfo struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Region string `protobuf:"bytes,2,opt,name=region" json:"region,omitempty"` AvailableZone string `protobuf:"bytes,3,opt,name=availableZone" json:"availableZone,omitempty"` }
DataCenterInfo is a struct with contains the zone information of the data center
type DependencyMicroService ¶
type DependencyMicroService struct { AppID string `protobuf:"bytes,1,opt,name=appId" json:"appId,omitempty"` ServiceName string `protobuf:"bytes,2,opt,name=serviceName" json:"serviceName,omitempty"` Version string `protobuf:"bytes,3,opt,name=version" json:"version,omitempty"` }
DependencyMicroService is a struct to keep dependency information for the microservice
type ExistenceIDResponse ¶
type ExistenceIDResponse struct { ServiceID string `json:"serviceId,omitempty"` SchemaID string `json:"schemaId,omitempty"` InstanceID string `json:"instanceId,omitempty"` }
ExistenceIDResponse is a structure for microservice with serviceID, schemaID and InstanceID
type Framework ¶
type Framework struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Version string `protobuf:"bytes,1,opt,name=version" json:"version,omitempty"` }
Framework is a struct which contains name and version of the Framework
type GetServicesInfoResponse ¶
type GetServicesInfoResponse struct {
AllServicesDetail []*ServiceDetail `protobuf:"bytes,2,rep,name=allServicesDetail" json:"allServicesDetail,omitempty"`
}
GetServicesInfoResponse is a struct to keep all the list of services.
type HealthCheck ¶
type HealthCheck struct { Mode string `protobuf:"bytes,1,opt,name=mode" json:"mode,omitempty"` Port int32 `protobuf:"varint,2,opt,name=port" json:"port,omitempty"` Interval int32 `protobuf:"varint,3,opt,name=interval" json:"interval,omitempty"` Times int32 `protobuf:"varint,4,opt,name=times" json:"times,omitempty"` }
HealthCheck is struct with contains mode, port and interval of sc from which it needs to poll information
type MicroServiceDependency ¶
type MicroServiceDependency struct { Consumer *DependencyMicroService `protobuf:"bytes,1,opt,name=consumer" json:"consumer,omitempty"` Providers []*DependencyMicroService `protobuf:"bytes,2,rep,name=providers" json:"providers,omitempty"` }
MicroServiceDependency is a struct to keep the all the dependency information
type MicroServiceInstanceChangedEvent ¶
type MicroServiceInstanceChangedEvent struct { Action string `protobuf:"bytes,2,opt,name=action" json:"action,omitempty"` Key *MicroServiceKey `protobuf:"bytes,3,opt,name=key" json:"key,omitempty"` Instance *proto.MicroServiceInstance `protobuf:"bytes,4,opt,name=instance" json:"instance,omitempty"` }
MicroServiceInstanceChangedEvent is a struct to store the Changed event information
type MicroServiceInstanceKey ¶
type MicroServiceInstanceKey struct { InstanceID string `protobuf:"bytes,1,opt,name=instanceId" json:"instanceId,omitempty"` ServiceID string `protobuf:"bytes,2,opt,name=serviceId" json:"serviceId,omitempty"` }
MicroServiceInstanceKey is a struct to key ID's of the microservice
type MicroServiceInstanceRequest ¶
type MicroServiceInstanceRequest struct {
Instance *proto.MicroServiceInstance `json:"instance"`
}
MicroServiceInstanceRequest is struct with microservice instance information
type MicroServiceInstancesResponse ¶
type MicroServiceInstancesResponse struct {
Instances []*proto.MicroServiceInstance `json:"instances,omitempty"`
}
MicroServiceInstancesResponse is a struct with instances information
type MicroServiceKey ¶
type MicroServiceKey struct { Tenant string `protobuf:"bytes,1,opt,name=tenant" json:"tenant,omitempty"` Project string `protobuf:"bytes,2,opt,name=project" json:"project,omitempty"` AppID string `protobuf:"bytes,3,opt,name=appId" json:"appId,omitempty"` ServiceName string `protobuf:"bytes,4,opt,name=serviceName" json:"serviceName,omitempty"` Version string `protobuf:"bytes,5,opt,name=version" json:"version,omitempty"` // contains filtered or unexported fields }
MicroServiceKey is a struct with key information about Microservice
type MicroServiceProvideresponse ¶
type MicroServiceProvideresponse struct {
Services []*proto.MicroService `json:"providers,omitempty"`
}
MicroServiceProvideresponse is a struct with provider information
type MicroServiceRequest ¶
type MicroServiceRequest struct {
Service *proto.MicroService `json:"service"`
}
MicroServiceRequest is a struct with microservice information
type MircroServiceDependencyRequest ¶
type MircroServiceDependencyRequest struct {
Dependencies []*MicroServiceDependency `json:"dependencies"`
}
MircroServiceDependencyRequest is a struct with dependencies request
type Options ¶
type Options struct { Addrs []string EnableSSL bool ConfigTenant string 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 (*RegistryClient) AddDependencies ¶
func (c *RegistryClient) AddDependencies(request *MircroServiceDependencyRequest) error
AddDependencies : 注册微服务的依赖关系
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 []*proto.FindService, opts ...CallOption) (map[string][]*proto.MicroServiceInstance, 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) ([]*proto.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) ([]*proto.MicroService, error)
GetAllMicroServices gets list of all the microservices registered with Service-Center
func (*RegistryClient) GetAllResources ¶
func (c *RegistryClient) GetAllResources(resource string, opts ...CallOption) ([]*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) (*proto.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) ([]*proto.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) HTTPDo ¶
func (c *RegistryClient) HTTPDo(method string, rawURL string, headers http.Header, body []byte) (resp *http.Response, err error)
HTTPDo makes the http request to Service-center with proper header, body and method
func (*RegistryClient) Health ¶
func (c *RegistryClient) Health() ([]*proto.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) Initialize ¶
func (c *RegistryClient) Initialize(opt Options) (err error)
Initialize initializes the Registry Client
func (*RegistryClient) RegisterMicroServiceInstance ¶
func (c *RegistryClient) RegisterMicroServiceInstance(microServiceInstance *proto.MicroServiceInstance) (string, error)
RegisterMicroServiceInstance registers the microservice instance to Servive-Center
func (*RegistryClient) RegisterService ¶
func (c *RegistryClient) RegisterService(microService *proto.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
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 *proto.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 *proto.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 ¶
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 ServiceDetail ¶
type ServiceDetail struct { MicroService *proto.MicroService `protobuf:"bytes,1,opt,name=microService" json:"microService,omitempty"` Instances []*proto.MicroServiceInstance `protobuf:"bytes,2,rep,name=instances" json:"instances,omitempty"` Providers []*proto.MicroService `protobuf:"bytes,5,rep,name=providers" json:"providers,omitempty"` Consumers []*proto.MicroService `protobuf:"bytes,6,rep,name=consumers" json:"consumers,omitempty"` Tags map[string]string `` /* 128-byte string literal not displayed */ MicroServiceVersions []string `protobuf:"bytes,8,rep,name=microServiceVersions" json:"microServiceVersions,omitempty"` }
ServiceDetail is a struct to store all the relevant information for a microservice
type ServicePath ¶
type ServicePath struct { Path string `protobuf:"bytes,1,opt,name=path" json:"path,omitempty"` Property map[string]string `` /* 136-byte string literal not displayed */ }
ServicePath is a struct with path and property information
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