Created
May 24, 2019 11:49
-
-
Save karl-gustav/8b91784cb18155ed3e14ec20b02b221f to your computer and use it in GitHub Desktop.
Super simple golang reverse proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"os" | |
) | |
var ( | |
apiURL = &url.URL{ | |
Scheme: "http", | |
Host: "35.228.103.113", | |
} | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
reverseProxy := httputil.NewSingleHostReverseProxy(apiURL) | |
reverseProxy.ServeHTTP(w, r) | |
}) | |
port := os.Getenv("PORT") | |
if port == "" { | |
port = "8080" | |
} | |
log.Println("Serving http://localhost:" + port) | |
log.Fatal(http.ListenAndServe(":"+port, nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment