Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Latest commit

 

History

History

httpset

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

go.serversets/httpset Build Status Godoc Reference

Package httpset provides round-robin balancing over a set of endpoints provided by go.serversets. Connection reuse is handled by the 'net/http' standard library.

Usage

package main

import (
	"log"

	"github.com/strava/go.serversets"
	"github.com/strava/go.serversets/httpset"
)

func main() {
	zookeepers := []string{"10.0.1.0", "10.0.5.0", "10.0.9.0"}
	watch, err := serversets.New(serversets.Production, "service_name", zookeepers).Watch()
	if err != nil {
		// This will be a problem connecting to Zookeeper
		log.Fatalf("Registration error: %v", err)
	}

	t := httpset.NewTransport(watch)
	t.UseHTTPS = true  // if scheme not specified, will use https

	client := &http.Client{
		Transport: t,
	}

	// Use the client as you normally would.
}

Dependencies

  • github.com/strava/go.serversets to get the server list. However, one can use a predefined set of servers by doing something like:

      t := httpset.NewTransport(nil)
      t.SetEndpoints([]string{"server1.com", "server2.com"})
    

Potential Improvements and Contributing

More better than round-robin. If you'd like, submit a pull request.