Skip to content

scottjbarr/etcd_service_discovery

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Small service discovery client for etcd

This is small library, that wraps the oficial etcd go client, to simplify service discovery.

GoDoc

How to register a service

// Create config
registryConfig := discovery.EtcdRegistryConfig = discovery.EtcdRegistryConfig{
		EtcdEndpoints: []string{"http://127.0.0.1:4001"}, //etcd instances
		ServiceName:   "core", //service type/name
		InstanceName:  "core1", //service instance name
		BaseUrl:       "127.0.0.1:8080", //base url to use to access service
	}

// Create client
registryClient, registryErr := discovery.New(registryConfig)
	if registryErr != nil {
		log.Panic(registryErr)
	}

// Register service to etcd
registryClient.Register()

How to obtain a instances by service type/name

response, err := client.ServicesByName("test")

if err != nil {
	log.Panic(err)
}

log.Println(response)

// Obtained output:
// [127.0.0.1:8080]

About

Service discovery client wrapper for etcd

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%