|
|
|
@ -6,12 +6,35 @@ import (
|
|
|
|
|
"log"
|
|
|
|
|
"net"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
|
app.Name = "what-is-my-ip"
|
|
|
|
|
app.Version = "0.1.0"
|
|
|
|
|
app.Usage = "Webapp that gives the IP address for incoming requests"
|
|
|
|
|
app.Action = action
|
|
|
|
|
|
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
|
cli.StringFlag{
|
|
|
|
|
Name: "address, a",
|
|
|
|
|
Value: ":3000",
|
|
|
|
|
EnvVar: "WHAT_IS_MY_IP_ADDRESS",
|
|
|
|
|
Usage: "Address and port to bind to",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.Run(os.Args)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func action(c *cli.Context) error {
|
|
|
|
|
http.HandleFunc("/", getIP)
|
|
|
|
|
fmt.Println("listening on port 3000")
|
|
|
|
|
http.ListenAndServe(":3000", nil)
|
|
|
|
|
address := c.String("address")
|
|
|
|
|
fmt.Printf("listening on %s\n", address)
|
|
|
|
|
return http.ListenAndServe(address, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getIP(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|