/sc-client

Primary LanguageGoApache License 2.0Apache-2.0

Service Center client for go

This is a service center client which helps the microservice to interact with Service Center for service-registration, discovery, instance registration etc.

This client implements API of Service Center.

Usage

registryClient, err := sc.NewClient(
	sc.Options{
		Addrs: []string{"127.0.0.1:30100"},
	})

declare and register micro service

var ms = new(discovery.MicroService)
var m = make(map[string]string)

m["abc"] = "abc"
m["def"] = "def"

ms.AppId = MSList[0].AppId
ms.ServiceName = MSList[0].ServiceName
ms.Version = MSList[0].Version
ms.Environment = MSList[0].Environment
ms.Properties = m
sid, err := registryClient.RegisterService(ms)

declare and register instance

	microServiceInstance := &discovery.MicroServiceInstance{
		Endpoints: []string{"rest://127.0.0.1:3000"},
		HostName:  hostname,
		Status:    sc.MSInstanceUP,
	}
	id, err := registryClient.RegisterMicroServiceInstance(microServiceInstance)