where

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5ddc0c11805c4b42190ccb53d46efb7702604105
parent 999c2a50deca90a88e320c45447367eb5116ddf5
Author: aabacchus <bvnfuller@gmail.com>
Date:   Fri, 19 Mar 2021 23:14:38 +0000

save latlng results to json file

Diffstat:
M.gitignore | 1+
Mwhere.go | 22+++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ creds.json +ips.json where whoips diff --git a/where.go b/where.go @@ -61,7 +61,27 @@ func main() { fmt.Println(resp.Mark) results[i] = resp.Mark } - fmt.Println(results) + //fmt.Println(results) + err = MarkersSaveJson(results, "ips.json") + if err != nil { + fmt.Printf("error saving as json: %s\n", err) + os.Exit(1) + } +} + +func MarkersSaveJson(m []Marker, fname string) error { + f, err := os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + if err != nil { + return err + } + defer f.Close() + + bytes, err := json.MarshalIndent(m, "", "\t") + if err != nil { + return err + } + _, err = f.Write(bytes) + return err } type Marker struct {