Skip to content
Snippets Groups Projects
main.go 528 B
Newer Older
  • Learn to ignore specific revisions
  • Nicolas PERNOUD's avatar
    Nicolas PERNOUD committed
    package main
    
    import (
    	"flag"
    	"net/http"
    	"strconv"
    	"strings"
    )
    
    var (
    	httpPort = flag.Int("http_port", 80, "HTTP port to serve on (defaults to 80)")
    )
    
    func main() {
    	// Parse the flags
    	flag.Parse()
    
    	mux := http.NewServeMux()
    	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    		query := r.URL.Query()
    		state := strings.Split(query.Get("state"), "-")[0]
    		host := r.Host
    		redir := "http://" + host + state
    		http.Redirect(w, r, redir, 302)
    	})
    
    	http.ListenAndServe(":"+strconv.Itoa(*httpPort), mux)
    }