Skip to content
/ consul Public

Consul service discovery provider with optional traffic balancing

License

Notifications You must be signed in to change notification settings

vinxi/consul

Repository files navigation

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

About

Consul service discovery provider with optional traffic balancing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages