forgot to add types.go
This commit is contained in:
parent
78b274c160
commit
fa50a2d618
28
types.go
28
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"`
|
||||
|
Loading…
Reference in New Issue
Block a user