Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.67 KB

README.md

File metadata and controls

54 lines (37 loc) · 1.67 KB

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