1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
612 B

package main
import (
"encoding/json"
"net/http"
"os/user"
"path/filepath"
)
func home(path string) string {
usr, err := user.Current()
if err != nil {
panic(err)
}
return filepath.Join(usr.HomeDir, path)
}
type freegeoipResponse struct {
Lat float64 `json:"latitude"`
Lng float64 `json:"longitude"`
}
func whereami() (lat float64, lng float64, err error) {
resp, err := http.Get("https://freegeoip.app/json/")
if err != nil {
return 0, 0, err
}
var res freegeoipResponse
err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
return 0, 0, err
}
return res.Lat, res.Lng, nil
}