Documentation ¶
Overview ¶
Package goproxy is a LoadBalancer based on httputil.ReverseProxy.
ExtractNameVersion and LoadBalance can be overridden in order to customize the behavior.
Example ¶
package main import ( "fmt" "log" "net/http" "github.com/creack/goproxy/registry" ) // ServiceRegistry is a local registry of services/versions var ServiceRegistry = registry.DefaultRegistry{ "service1": { "v1": { "localhost:9091", "localhost:9092", }, }, } func main() { http.HandleFunc("/", NewMultipleHostReverseProxy(ServiceRegistry)) http.HandleFunc("/health", func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "%v\n", ServiceRegistry) }) println("ready") log.Fatal(http.ListenAndServe(":9090", nil)) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidService = errors.New("invalid service/version")
)
Common errors
View Source
var ExtractNameVersion = extractNameVersion
ExtractNameVersion is called to lookup the service name / version from the requested URL. It should update the URL's Path to reflect the target expectation.
View Source
var LoadBalance = loadBalance
LoadBalance is the default balancer which will use a random endpoint for the given service name/version.
Functions ¶
func NewMultipleHostReverseProxy ¶
func NewMultipleHostReverseProxy(reg registry.Registry) http.HandlerFunc
NewMultipleHostReverseProxy creates a reverse proxy handler that will randomly select a host from the passed `targets`
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.