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() host := strings.Split(query.Get("state"), "-")[0] state := strings.Split(query.Get("state"), "-")[1] usagePointId := query.Get("usage_point_id") code := query.Get("code") redir := "http://" + host + "?code=" + code + "?state="+ state +"&usage_point_id=" + usagePointId http.Redirect(w, r, redir, 302) }) http.ListenAndServe(":"+strconv.Itoa(*httpPort), mux) }