Giter Club home page Giter Club logo

etcd-discovery's Introduction

Etcd Discovery v7.1.0

This is a golang package for managing services over the decentralized key-value store etcd.

https://github.com/etcd-io/etcd

To install it:

go get github.com/Scalingo/etcd-discovery/service/v7

API

Register a service

/*
 * First argument is the name of the service
 * Then a struct containing the service informations
 * The registeration will stop when the context will be canceled.
 * It will return the service uuid and a channel which will send back any modifications made to the service by the other host of the same service. This is usefull for credential synchronisation.
 */
ctx, cancel := context.WithCancel(context.Background())
registration := service.Register(
  ctx,
  "my-service",
  &service.Host{
    Hostname: "public-domain.dev",
    Ports: service.Ports{
      "http":  "80",
      "https": "443",
    },
    Critical:       true,
    User:           gopassword.Generate(10),
    Password:       gopassword.Generate(10),
    Public: true,
    PrivateHostname: "node-1.internal.dev",
    PrivatePorts: service.ports{
      "http":  "8080",
      "https": "80443",
    },
  })

This will create two different etcd keys:

  • /services/name_of_service/you-service-uuid-node-1.internal.dev containing:
{
   "name": "public-domain.dev",
   "service_name": "my-service",
   "user": "user",
   "password": "secret",
   "public": true,
   "private_hostname": "node-1.internal.dev",
   "private_ports": {
      "http": "8080",
      "https": "80443"
   },
   "critcal": true,
   "uuid": "your-service-uuid-node-1.internal.dev",
   "ports":{
      "http":"80",
      "https":"443"
   }
}
  • /service_infos/name_of_service containing:
{
   "name": "my-service",
   "critical": true,
   "hostname": "public-domain.dev",
   "user": "user",
   "password": "password",
   "ports": {
      "http": "80",
      "https": "443"
   },
   "public": true
}

Subscribe to new service

When a service is added from another host, if you want your application to notice it and communicating with it, it is necessary to watch these notifications.

newHosts := service.SubscribeNew("name_of_service")
for host := range newHosts {
  fmt.Println(host.Name, "has registered")
}

Watch down services

deadHosts := service.SubscribeDown("name_of_service")
for hostname := range deadHosts {
  fmt.Println(hostname, "is dead, RIP")
}

Generate the mocks

Generate the mocks with:

for interface in $(grep --extended-regexp --no-message --no-filename "type .* interface" ./service/* | cut -d " " -f 2)
do
  mockgen -destination service/servicemock/gomock_$(echo $interface | tr '[:upper:]' '[:lower:]').go -package servicemock github.com/Scalingo/etcd-discovery/v7/service $interface
done

Release a New Version

Bump new version number in CHANGELOG.md and README.md.

Commit, tag and create a new release:

git add CHANGELOG.md README.md
git commit -m "Bump v7.1.0"
git tag v7.1.0
git push origin master
git push --tags
hub release create v7.1.0

The title of the release should be the version number and the text of the release is the same as the changelog.

etcd-discovery's People

Contributors

soulou avatar john-scalingo avatar etiennem avatar dependabot[bot] avatar brandon-welsch avatar johnsudaar avatar

Stargazers

viphxin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.