diff --git a/types.go b/types.go index 8b4831b..af44a00 100644 --- a/types.go +++ b/types.go @@ -1,6 +1,12 @@ package main -import "time" +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "time" +) type device struct { Name string `json:"name"` @@ -111,6 +117,26 @@ type output struct { Links []link `json:"links"` } +func (o *output) writeToFile() error { + file, err := json.MarshalIndent(o, "", " ") + if err != nil { + return fmt.Errorf("can't marshal to json: %+v", o) + } + + // write to file + if _, err := os.Stat("output"); os.IsNotExist(err) { + err = os.Mkdir("output", 0755) + if err != nil { + return fmt.Errorf("can't create output folder") + } + } + err = ioutil.WriteFile("output/meshviewer.json", file, 0644) + if err != nil { + return fmt.Errorf("can't write to json file meshviewer.json") + } + return nil +} + type apiResponse struct { StatusCode int `json:"statusCode"` Error string `json:"error"`