]> git.scottworley.com Git - planeteer/commitdiff
Generalize json-slurping
authorScott Worley <sworley@chkno.net>
Sat, 15 Sep 2012 20:19:46 +0000 (13:19 -0700)
committerScott Worley <sworley@chkno.net>
Sat, 15 Sep 2012 20:19:46 +0000 (13:19 -0700)
planeteer.go

index eb78bce1ebb966b35f0720da2ccf59672327fb8a..4976abe131d1ececa2a2b8ec256cfae2d39b609b 100644 (file)
@@ -133,13 +133,21 @@ type planet_data struct {
        i2p, i2c    []string       // Generated; not read from file
 }
 
        i2p, i2c    []string       // Generated; not read from file
 }
 
-func ReadData() (data planet_data) {
-       f, err := os.Open(*planet_data_file)
+func json_slurp(filename string, receptacle interface{}) error {
+       f, err := os.Open(filename)
        if err != nil {
        if err != nil {
-               panic(err)
+               return err
        }
        defer f.Close()
        }
        defer f.Close()
-       err = json.NewDecoder(f).Decode(&data)
+       err = json.NewDecoder(f).Decode(receptacle)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+func ReadData() (data planet_data) {
+       err := json_slurp(*planet_data_file, &data)
        if err != nil {
                panic(err)
        }
        if err != nil {
                panic(err)
        }