Tiny utility to deal with IP
go get github.com/shamsher31/goip
package main
import (
"fmt"
"github.com/shamsher31/goip"
"net/http"
)
func reqHandler(w http.ResponseWriter, req *http.Request) {
// Returns 1.187.109.235, nil
fmt.Println(ip.Remote(req))
}
func main() {
// Returns 10.102.29.20, nil
fmt.Println(ip.Local())
// Run simple server to test
http.HandleFunc("/", reqHandler)
http.ListenAndServe(":8090", nil)
}
This package will be useful when you write application which require you to deal with local or remote IP of the requested host.
MIT © Shamsher Ansari