Skip to content

Instantly share code, notes, and snippets.

@9072997
Created February 1, 2022 13:49
Show Gist options
  • Save 9072997/7d518ef23d022527be844ce409508ccc to your computer and use it in GitHub Desktop.
Save 9072997/7d518ef23d022527be844ce409508ccc to your computer and use it in GitHub Desktop.
CORS enabled HTTP server that tells users their IP
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