vulcan
vulcan copied to clipboard
Load Balancer example from quickstart keeps getting 404 not found
I'm trying the load balancer example to reach https://www.google.com (i.e. single upstream node) from localhost. Such that when I do,
curl localhost:8000
It should return the page from Google. The problem is that I keep getting a 404 not found. Any idea please?
$ curl "http://localhost:8000/"
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>404.</b> <ins>That’s an error.</ins>
<p>The requested URL <code>/</code> was not found on this server. <ins>That’s all we know.</ins>
Here is my code.
package main
import (
"log"
"net/http"
"os"
"time"
"github.com/mailgun/vulcan"
"github.com/mailgun/vulcan/endpoint"
"github.com/mailgun/vulcan/loadbalance"
"github.com/mailgun/vulcan/loadbalance/roundrobin"
"github.com/mailgun/vulcan/location/httploc"
"github.com/mailgun/vulcan/route"
)
var PORT string = os.Getenv("PORT")
var smtpServers = []string{"https://www.google.com"}
func NewBalancer(servers []string) loadbalance.LoadBalancer {
// Create a round robin load balancer with some endpoints
rr, err := roundrobin.NewRoundRobin()
if err != nil {
log.Fatalf("Error: %s", err)
}
for _, s := range servers {
rr.AddEndpoint(endpoint.MustParseUrl(s))
}
return rr
}
func main() {
rr := NewBalancer(smtpServers)
// Create a http location with the load balancer we've just added
loc, err := httploc.NewLocation("loc1", rr)
if err != nil {
log.Fatalf("Error: %s", err)
}
// Create a proxy server that routes all requests to "loc1"
proxy, err := vulcan.NewProxy(&route.ConstRouter{Location: loc})
if err != nil {
log.Fatalf("Error: %s", err)
}
// Proxy acts as http handler:
server := &http.Server{
Addr: ":" + PORT,
Handler: proxy,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Println("Listening on port " + PORT)
server.ListenAndServe()
if err != nil {
log.Panic(err)
}
}