Created
February 1, 2022 13:49
-
-
Save 9072997/7d518ef23d022527be844ce409508ccc to your computer and use it in GitHub Desktop.
CORS enabled HTTP server that tells users their IP
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 ( | |
"net" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) { | |
resp.Header().Set("Access-Control-Allow-Origin", "*") | |
ip, _, err := net.SplitHostPort(req.RemoteAddr) | |
if err != nil { | |
http.Error(resp, err.Error(), http.StatusInternalServerError) | |
return | |
} | |
resp.Write([]byte(ip)) | |
}) | |
panic(http.ListenAndServe(":80", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment