github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/lb/fnlb/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"flag"
     6  	"fmt"
     7  	"net/http"
     8  	"os"
     9  	"strings"
    10  
    11  	"github.com/iron-io/functions/lb"
    12  )
    13  
    14  var (
    15  	fnodes  string
    16  	flisten string
    17  )
    18  
    19  func init() {
    20  	flag.StringVar(&fnodes, "nodes", "127.0.0.1:8080", "comma separated list of IronFunction nodes")
    21  	flag.StringVar(&flisten, "listen", "0.0.0.0:8081", "listening port for incoming connections")
    22  	flag.Parse()
    23  }
    24  
    25  func main() {
    26  	nodes := strings.Split(fnodes, ",")
    27  	p := lb.ConsistentHashReverseProxy(context.Background(), nodes)
    28  	fmt.Println("forwarding calls to", nodes)
    29  	fmt.Println("listening to", flisten)
    30  	if err := http.ListenAndServe(flisten, p); err != nil {
    31  		fmt.Fprintln(os.Stderr, "could not start server. error:", err)
    32  		os.Exit(1)
    33  	}
    34  }