Added Go: Basic Http Redirect

This commit is contained in:
2025-01-25 22:42:54 +01:00
parent cadedc475f
commit bc97f60438

33
Go/BasicHttpRedirect.go Normal file
View File

@@ -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 <Path to Binary>`
* Systemd Service Example
[Unit]
Description=Redirect port 80 to target app
After=network.target
[Service]
Type=simple
User=<user>
ExecStart=/<Path to Binary>
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)
}