Created
September 26, 2019 16:45
-
-
Save gregtap/27f25ea4d52a8d7c12787f9025ff9ffc to your computer and use it in GitHub Desktop.
dumb redirect
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 ( | |
"fmt" | |
"net/http" | |
"os" | |
) | |
var targetDomain = fmt.Sprintf("%s", getEnv("TARGET_DOMAIN", "https://google.com")) | |
func getEnv(key, defaultValue string) string { | |
value := os.Getenv(key) | |
if len(value) == 0 { | |
return defaultValue | |
} | |
return value | |
} | |
func redirect(w http.ResponseWriter, r *http.Request) { | |
http.Redirect(w, r, targetDomain, http.StatusMovedPermanently) | |
} | |
func main() { | |
port := fmt.Sprintf(":%s", getEnv("PORT", "8000")) | |
http.HandleFunc("/", redirect) | |
fmt.Println("🤤 301 dumb redirect server") | |
fmt.Println("Redirects to %s", targetDomain) | |
fmt.Println("Listening on port %s...", port) | |
http.ListenAndServe(port, nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment