From: Scott Worley Date: Sat, 15 Sep 2012 20:19:46 +0000 (-0700) Subject: Generalize json-slurping X-Git-Url: http://git.scottworley.com/planeteer/commitdiff_plain/091c628026edc6f81d851bd1d070edd34af20b67 Generalize json-slurping --- diff --git a/planeteer.go b/planeteer.go index eb78bce..4976abe 100644 --- a/planeteer.go +++ b/planeteer.go @@ -133,13 +133,21 @@ type planet_data struct { 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 { - panic(err) + return err } 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) }