Consul service discovery provider with optional traffic balancing
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
_examples
.editorconfig
.gitignore
.travis.yml
History.md
LICENSE
README.md
client.go
client_test.go
config.go
config_test.go
consul.go
consul_test.go
retrier.go
retrier_test.go
version.go

README.md

consul Build Status GoDoc Coverage Status Go Report Card API

Consul plugin for simple dynamic service discovery and optional traffic balancing in vinxi proxies.

Supports multiple Consul servers, non-blocking multi-thread service discovery, retry policy on discovery error and transparent fallback to the next Consul server available.

Installation

go get -u gopkg.in/vinxi/consul.v0

API

See godoc reference.

Example

Server discovery with default roundrobin balancer

package main

import (
  "fmt"
  "gopkg.in/vinxi/consul.v0"
  "gopkg.in/vinxi/forward.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create the Consul client
  cc := consul.New(consul.NewConfig("web", "http://demo.consul.io"))

  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})
  vs.Use(cc)

  fw, _ := forward.New(forward.PassHostHeader(true))
  vs.UseFinalHandler(fw)

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

License

MIT