forgot to add types.go

This commit is contained in:
Nils Stinnesbeck 2021-01-02 22:17:15 +01:00
parent 78b274c160
commit fa50a2d618

View File

@ -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"`