From bc97f6043838136876f7bff2a25559686cf9df0e Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Sat, 25 Jan 2025 22:42:54 +0100 Subject: [PATCH] Added Go: Basic Http Redirect --- Go/BasicHttpRedirect.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Go/BasicHttpRedirect.go diff --git a/Go/BasicHttpRedirect.go b/Go/BasicHttpRedirect.go new file mode 100644 index 0000000..9cb85a3 --- /dev/null +++ b/Go/BasicHttpRedirect.go @@ -0,0 +1,33 @@ +/* + * Update target on line 27 + * Run `go build BasicHttpRedirect.go` + * Move resulting binary to target system + * Allow port 80 using `setcap CAP_NET_BIND_SERVICE=+eip ` + * Systemd Service Example +[Unit] +Description=Redirect port 80 to target app +After=network.target + +[Service] +Type=simple +User= +ExecStart=/ +Restart=on-failure + +[Install] +WantedBy=multi-user.target + +*/ + +package main + +import ("net/http") + +func redirect(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "http://Target:Port", 302) +} + +func main() { + http.HandleFunc("/", redirect) + http.ListenAndServe(":80", nil) +}