From 37bc1c620cf43e217da0189c11137a83827831b5 Mon Sep 17 00:00:00 2001 From: Amir Mofasser Date: Mon, 5 Feb 2018 22:36:40 +0100 Subject: [PATCH 1/3] Minor changes to tests --- CHANGELOG.md | 6 ++++++ config_test.go | 2 +- resourcelink_test.go | 31 +++++++++++++++---------------- sensor.go | 28 +++++++--------------------- sensor_test.go | 8 ++++---- 5 files changed, 33 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b53817d..f4b40f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.0.0-beta.2 + +## 1.0.0-beta.1 +* `Sensor.State` and `Sensor.Config` is now `interface{}` since these varry depending on the type +* As of this release `Gitflow` is obsolete. + ## 1.0.0-alpha.5 * Added `SetState` receivers to `Group` and `Light`. * Renamed `SetLight` to `SetLightState` for a more consistent naming convention. diff --git a/config_test.go b/config_test.go index 48ffd17..85d0f53 100644 --- a/config_test.go +++ b/config_test.go @@ -104,5 +104,5 @@ func TestDeleteUser(t *testing.T) { t.Logf("Deleted user '%s' (%s)", user.Name, user.Username) } } - + } diff --git a/resourcelink_test.go b/resourcelink_test.go index bc5650c..f1e348c 100644 --- a/resourcelink_test.go +++ b/resourcelink_test.go @@ -18,10 +18,10 @@ func TestGetResourcelinks(t *testing.T) { t.Logf(" Name: %s", resourcelink.Name) t.Logf(" Description: %s", resourcelink.Description) t.Logf(" Type: %s", resourcelink.Type) - t.Logf(" ClassID: %s", resourcelink.ClassID) + t.Logf(" ClassID: %d", resourcelink.ClassID) t.Logf(" Owner: %s", resourcelink.Owner) t.Logf(" Links: %s", resourcelink.Links) - t.Logf(" ID: %s", resourcelink.ID) + t.Logf(" ID: %d", resourcelink.ID) } } @@ -39,10 +39,10 @@ func TestGetResourcelink(t *testing.T) { t.Logf("Name: %s", l.Name) t.Logf("Description: %s", l.Description) t.Logf("Type: %s", l.Type) - t.Logf("ClassID: %s", l.ClassID) + t.Logf("ClassID: %d", l.ClassID) t.Logf("Owner: %s", l.Owner) t.Logf("Links: %s", l.Links) - t.Logf("ID: %s", l.ID) + t.Logf("ID: %d", l.ID) break } } @@ -60,12 +60,12 @@ func TestCreateResourcelink(t *testing.T) { resp, err := b.CreateResourcelink(resourcelink) if err != nil { t.Fatal(err) - } else { - t.Logf("Resourcelink created") - for k, v := range resp.Success { - t.Logf("%v: %s", k, v) - } } + t.Logf("Resourcelink created") + for k, v := range resp.Success { + t.Logf("%v: %s", k, v) + } + } func TestUpdateResourcelink(t *testing.T) { @@ -77,12 +77,12 @@ func TestUpdateResourcelink(t *testing.T) { }) if err != nil { t.Fatal(err) - } else { - t.Logf("Resourcelink %d updated", id) - for k, v := range resp.Success { - t.Logf("%v: %s", k, v) - } } + t.Logf("Resourcelink %d updated", id) + for k, v := range resp.Success { + t.Logf("%v: %s", k, v) + } + } func TestDeleteResourcelink(t *testing.T) { @@ -91,7 +91,6 @@ func TestDeleteResourcelink(t *testing.T) { err := b.DeleteResourcelink(1) if err != nil { t.Fatal(err) - } else { - t.Logf("Resourcelink %d deleted", id) } + t.Logf("Resourcelink %d deleted", id) } diff --git a/sensor.go b/sensor.go index 62b0525..9920edf 100644 --- a/sensor.go +++ b/sensor.go @@ -2,30 +2,16 @@ package huego // Sensor represents a bridge sensor https://developers.meethue.com/documentation/sensors-api type Sensor struct { - State interface{} `json:"state,omitempty"` + State interface{} `json:"state,omitempty"` Config interface{} `json:"config,omitempty"` - Name string `json:"name,omitempty"` - Type string `json:"type,omitempty"` - ModelID string `json:"modelid,omitempty"` - ManufacturerName string `json:"manufacturername,omitempty"` - SwVersion string `json:"swversion,omitemptyn"` - ID int `json:",omitempty"` + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` + ModelID string `json:"modelid,omitempty"` + ManufacturerName string `json:"manufacturername,omitempty"` + SwVersion string `json:"swversion,omitemptyn"` + ID int `json:",omitempty"` } -// // SensorState defines the state a sensor has -// type SensorState struct { -// Daylight string `json:"daylight,omitempty"` -// LastUpdated string `json:"lastupdated,omitempty"` -// } - -// // SensorConfig defines the configuration of a sensor -// type SensorConfig struct { -// On bool `json:"on,omitempty"` -// Configured bool `json:"configured,omitempty"` -// SunriseOffset int `json:"sunriseoffset,omitempty"` -// SunsetOffset int `json:"sunsetoffset,omitempty"` -// } - // NewSensor defines a list of sensors discovered the last time the bridge performed a sensor discovery. // Also stores the timestamp the last time a discovery was performed. type NewSensor struct { diff --git a/sensor_test.go b/sensor_test.go index c6c6025..0f095fa 100644 --- a/sensor_test.go +++ b/sensor_test.go @@ -61,7 +61,7 @@ func TestCreateSensor(t *testing.T) { }) if err != nil { t.Fatal(err) - } + } t.Logf("Sensor created") for k, v := range resp.Success { t.Logf("%v: %s", k, v) @@ -74,7 +74,7 @@ func TestFindSensors(t *testing.T) { resp, err := b.FindSensors() if err != nil { t.Fatal(err) - } + } for k, v := range resp.Success { t.Logf("%v: %s", k, v) } @@ -110,7 +110,7 @@ func TestUpdateSensor(t *testing.T) { }) if err != nil { t.Fatal(err) - } + } for k, v := range resp.Success { t.Logf("%v: %s", k, v) } @@ -123,6 +123,6 @@ func TestDeleteSensor(t *testing.T) { err := b.DeleteSensor(id) if err != nil { t.Fatal(err) - } + } t.Logf("Sensor %d deleted", id) } From 534f3f7e9332fef995dca19c704e0bfb9e0943a0 Mon Sep 17 00:00:00 2001 From: Amir Mofasser Date: Sat, 3 Mar 2018 09:19:31 +0100 Subject: [PATCH 2/3] Added unmarshal fan-in function --- bridge.go | 109 +++++++++++++++++++++++++------------------------ bridge_test.go | 33 +++++++++++++++ group_test.go | 22 +++++----- huego.go | 19 +++++++++ 4 files changed, 118 insertions(+), 65 deletions(-) diff --git a/bridge.go b/bridge.go index b974c10..f5b2d49 100644 --- a/bridge.go +++ b/bridge.go @@ -57,7 +57,7 @@ func (b *Bridge) GetConfig() (*Config, error) { return nil, err } - err = json.Unmarshal(res, &config) + err = unmarshal(res, &config) if err != nil { return nil, err } @@ -99,7 +99,7 @@ func (b *Bridge) CreateUser(n string) (string, error) { return "", err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return "", err } @@ -142,7 +142,7 @@ func (b *Bridge) UpdateConfig(c *Config) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -170,7 +170,7 @@ func (b *Bridge) DeleteUser(n string) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -196,7 +196,7 @@ func (b *Bridge) GetFullState() (*Datastore, error) { return nil, err } - err = json.Unmarshal(res, &ds) + err = unmarshal(res, &ds) if err != nil { return nil, err } @@ -225,7 +225,8 @@ func (b *Bridge) GetGroups() ([]Group, error) { return nil, err } - err = json.Unmarshal(res, &m) + //err = unmarshal(res, &m) + err = unmarshal(res, &m) if err != nil { return nil, err } @@ -262,7 +263,7 @@ func (b *Bridge) GetGroup(i int) (*Group, error) { return nil, err } - err = json.Unmarshal(res, &g) + err = unmarshal(res, &g) if err != nil { return nil, err } @@ -293,7 +294,7 @@ func (b *Bridge) SetGroupState(i int, l State) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -316,18 +317,18 @@ func (b *Bridge) UpdateGroup(i int, l Group) (*Response, error) { if err != nil { return nil, err } - + data, err := json.Marshal(&l) if err != nil { return nil, err } - + res, err := put(url, data) if err != nil { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -360,7 +361,7 @@ func (b *Bridge) CreateGroup(g Group) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -369,7 +370,7 @@ func (b *Bridge) CreateGroup(g Group) (*Response, error) { if err != nil { return nil, err } - + return resp, nil } @@ -389,7 +390,7 @@ func (b *Bridge) DeleteGroup(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -420,7 +421,7 @@ func (b *Bridge) GetLights() ([]Light, error) { return nil, err } - err = json.Unmarshal(res, &m) + err = unmarshal(res, &m) if err != nil { return nil, err } @@ -457,7 +458,7 @@ func (b *Bridge) GetLight(i int) (*Light, error) { return light, err } - err = json.Unmarshal(res, &light) + err = unmarshal(res, &light) if err != nil { return light, err } @@ -489,7 +490,7 @@ func (b *Bridge) SetLightState(i int, l State) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -519,7 +520,7 @@ func (b *Bridge) FindLights() (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -548,7 +549,7 @@ func (b *Bridge) GetNewLights() (*NewLight, error) { return nil, err } - _ = json.Unmarshal(res, &n) + _ = unmarshal(res, &n) lights := make([]string, 0, len(n)) var lastscan string @@ -586,7 +587,7 @@ func (b *Bridge) DeleteLight(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -618,7 +619,7 @@ func (b *Bridge) UpdateLight(i int, light Light) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -652,7 +653,7 @@ func (b *Bridge) GetResourcelinks() ([]*Resourcelink, error) { return nil, err } - err = json.Unmarshal(res, &r) + err = unmarshal(res, &r) if err != nil { return nil, err } @@ -685,7 +686,7 @@ func (b *Bridge) GetResourcelink(i int) (*Resourcelink, error) { return nil, err } - err = json.Unmarshal(res, &g) + err = unmarshal(res, &g) if err != nil { return nil, err } @@ -714,7 +715,7 @@ func (b *Bridge) CreateResourcelink(s *Resourcelink) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -747,7 +748,7 @@ func (b *Bridge) UpdateResourcelink(i int, resourcelink *Resourcelink) (*Respons return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -776,7 +777,7 @@ func (b *Bridge) DeleteResourcelink(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -807,7 +808,7 @@ func (b *Bridge) GetRules() ([]*Rule, error) { return nil, err } - err = json.Unmarshal(res, &r) + err = unmarshal(res, &r) if err != nil { return nil, err } @@ -843,7 +844,7 @@ func (b *Bridge) GetRule(i int) (*Rule, error) { return nil, err } - err = json.Unmarshal(res, &g) + err = unmarshal(res, &g) if err != nil { return nil, err } @@ -872,7 +873,7 @@ func (b *Bridge) CreateRule(s *Rule) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -906,7 +907,7 @@ func (b *Bridge) UpdateRule(i int, rule *Rule) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -935,7 +936,7 @@ func (b *Bridge) DeleteRule(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -966,7 +967,7 @@ func (b *Bridge) GetScenes() ([]Scene, error) { return nil, err } - err = json.Unmarshal(res, &m) + err = unmarshal(res, &m) scenes := make([]Scene, 0, len(m)) for i, g := range m { @@ -997,12 +998,12 @@ func (b *Bridge) GetScene(i string) (*Scene, error) { return nil, err } - err = json.Unmarshal(res, &l) + err = unmarshal(res, &l) if err != nil { return nil, err } - err = json.Unmarshal(res, &g) + err = unmarshal(res, &g) if err != nil { return nil, err } @@ -1032,7 +1033,7 @@ func (b *Bridge) UpdateScene(id string, s *Scene) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1067,7 +1068,7 @@ func (b *Bridge) SetSceneLightState(id string, iid int, l *State) (*Response, er return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1103,7 +1104,7 @@ func (b *Bridge) RecallScene(id string, gid int) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1136,7 +1137,7 @@ func (b *Bridge) CreateScene(s *Scene) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1164,7 +1165,7 @@ func (b *Bridge) DeleteScene(id string) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -1195,7 +1196,7 @@ func (b *Bridge) GetSchedules() ([]*Schedule, error) { return nil, err } - err = json.Unmarshal(res, &r) + err = unmarshal(res, &r) if err != nil { return nil, err } @@ -1231,7 +1232,7 @@ func (b *Bridge) GetSchedule(i int) (*Schedule, error) { return nil, err } - err = json.Unmarshal(res, &g) + err = unmarshal(res, &g) if err != nil { return nil, err } @@ -1260,7 +1261,7 @@ func (b *Bridge) CreateSchedule(s *Schedule) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1294,7 +1295,7 @@ func (b *Bridge) UpdateSchedule(i int, schedule *Schedule) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1323,7 +1324,7 @@ func (b *Bridge) DeleteSchedule(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -1354,7 +1355,7 @@ func (b *Bridge) GetSensors() ([]Sensor, error) { return nil, err } - err = json.Unmarshal(res, &s) + err = unmarshal(res, &s) if err != nil { return nil, err } @@ -1389,7 +1390,7 @@ func (b *Bridge) GetSensor(i int) (*Sensor, error) { return r, err } - err = json.Unmarshal(res, &r) + err = unmarshal(res, &r) if err != nil { return r, err } @@ -1418,7 +1419,7 @@ func (b *Bridge) CreateSensor(s *Sensor) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1448,7 +1449,7 @@ func (b *Bridge) FindSensors() (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1478,7 +1479,7 @@ func (b *Bridge) GetNewSensors() (*NewSensor, error) { return nil, err } - err = json.Unmarshal(res, &n) + err = unmarshal(res, &n) sensors := make([]*Sensor, 0, len(n)) for i, l := range n { @@ -1491,7 +1492,7 @@ func (b *Bridge) GetNewSensors() (*NewSensor, error) { } } - err = json.Unmarshal(res, &result) + err = unmarshal(res, &result) if err != nil { return nil, err } @@ -1522,7 +1523,7 @@ func (b *Bridge) UpdateSensor(i int, sensor *Sensor) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1551,7 +1552,7 @@ func (b *Bridge) DeleteSensor(i int) error { return err } - _ = json.Unmarshal(res, &a) + _ = unmarshal(res, &a) _, err = handleResponse(a) if err != nil { @@ -1580,7 +1581,7 @@ func (b *Bridge) UpdateSensorConfig(i int, c interface{}) (*Response, error) { return nil, err } - err = json.Unmarshal(res, &a) + err = unmarshal(res, &a) if err != nil { return nil, err } @@ -1614,7 +1615,7 @@ func (b *Bridge) GetCapabilities() (*Capabilities, error) { return nil, err } - err = json.Unmarshal(res, &s) + err = unmarshal(res, &s) if err != nil { return nil, err } diff --git a/bridge_test.go b/bridge_test.go index c54618a..136f7b7 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -1 +1,34 @@ package huego_test + +import ( + "os" + "testing" + "github.com/amimof/huego" +) + +func TestLogin(t *testing.T) { + b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_PASSWORD")) + c, err := b.GetConfig() + if err != nil { + t.Fatal(err) + } + t.Logf("Logged in and got config which means that we are authorized") + t.Logf("Name: %s, SwVersion: %s", c.Name, c.SwVersion) +} + +func TestLoginUnauthorized(t *testing.T) { + b := huego.New(os.Getenv("HUE_HOSTNAME"), "") + b = b.Login("invalid_password") + _, err := b.GetLights() + if err != nil { + t.Fatal(err) + /* + We should do something here to check if the user is allowed + the requested resource (in this case Config). A simple err + shouldn't fail the test. + */ + } + t.Logf("Bridge: %s, Username: %s", b.Host, b.User) + t.Log("User logged in and authenticated which isn't what we want") +} + diff --git a/group_test.go b/group_test.go index f8ea918..5ae18e0 100644 --- a/group_test.go +++ b/group_test.go @@ -138,17 +138,6 @@ func TestSetGroupState(t *testing.T) { } } -func TestDeleteGroup(t *testing.T) { - b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME")) - id := 3 - err := b.DeleteGroup(id) - if err != nil { - t.Fatal(err) - } else { - t.Logf("Deleted group with id: %d", id) - } -} - func TestRenameGroup(t *testing.T) { bridge := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME")) id := 3 @@ -345,3 +334,14 @@ func TestSetStateGroup(t *testing.T) { } t.Logf("State set successfully on group %d", id) } + +func TestDeleteGroup(t *testing.T) { + b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME")) + id := 3 + err := b.DeleteGroup(id) + if err != nil { + t.Fatal(err) + } else { + t.Logf("Deleted group with id: %d", id) + } +} \ No newline at end of file diff --git a/huego.go b/huego.go index f8fe10f..4ea5487 100644 --- a/huego.go +++ b/huego.go @@ -61,6 +61,24 @@ func handleResponse(a []*APIResponse) (*Response, error) { return resp, nil } +// unmarshal will try to unmarshal data into APIResponse so that we can +// return the actual error returned by the bridge http API as an error struct. +func unmarshal(data []byte, v interface{}) error { + err := json.Unmarshal(data, &v) + if err != nil { + var a []*APIResponse + err = json.Unmarshal(data, &a) + if err != nil { + return err + } + _, err = handleResponse(a) + if err != nil { + return err + } + } + return nil +} + func get(url string) ([]byte, error) { req, err := http.NewRequest("GET", url, nil) @@ -77,6 +95,7 @@ func get(url string) ([]byte, error) { defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) + if err != nil { return nil, err } From 2da5e019ec258bf815ac61e6a86e17c689e4d16a Mon Sep 17 00:00:00 2001 From: Amir Mofasser Date: Sat, 3 Mar 2018 09:21:10 +0100 Subject: [PATCH 3/3] go fmt --- bridge.go | 6 +++--- bridge_test.go | 5 ++--- group_test.go | 2 +- huego.go | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bridge.go b/bridge.go index f5b2d49..43514f6 100644 --- a/bridge.go +++ b/bridge.go @@ -317,12 +317,12 @@ func (b *Bridge) UpdateGroup(i int, l Group) (*Response, error) { if err != nil { return nil, err } - + data, err := json.Marshal(&l) if err != nil { return nil, err } - + res, err := put(url, data) if err != nil { return nil, err @@ -370,7 +370,7 @@ func (b *Bridge) CreateGroup(g Group) (*Response, error) { if err != nil { return nil, err } - + return resp, nil } diff --git a/bridge_test.go b/bridge_test.go index 136f7b7..6cad48c 100644 --- a/bridge_test.go +++ b/bridge_test.go @@ -1,9 +1,9 @@ package huego_test import ( + "github.com/amimof/huego" "os" "testing" - "github.com/amimof/huego" ) func TestLogin(t *testing.T) { @@ -24,11 +24,10 @@ func TestLoginUnauthorized(t *testing.T) { t.Fatal(err) /* We should do something here to check if the user is allowed - the requested resource (in this case Config). A simple err + the requested resource (in this case Config). A simple err shouldn't fail the test. */ } t.Logf("Bridge: %s, Username: %s", b.Host, b.User) t.Log("User logged in and authenticated which isn't what we want") } - diff --git a/group_test.go b/group_test.go index 5ae18e0..14f1fb6 100644 --- a/group_test.go +++ b/group_test.go @@ -344,4 +344,4 @@ func TestDeleteGroup(t *testing.T) { } else { t.Logf("Deleted group with id: %d", id) } -} \ No newline at end of file +} diff --git a/huego.go b/huego.go index 4ea5487..c15ea40 100644 --- a/huego.go +++ b/huego.go @@ -64,7 +64,7 @@ func handleResponse(a []*APIResponse) (*Response, error) { // unmarshal will try to unmarshal data into APIResponse so that we can // return the actual error returned by the bridge http API as an error struct. func unmarshal(data []byte, v interface{}) error { - err := json.Unmarshal(data, &v) + err := json.Unmarshal(data, &v) if err != nil { var a []*APIResponse err = json.Unmarshal(data, &a) @@ -95,7 +95,7 @@ func get(url string) ([]byte, error) { defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) - + if err != nil { return nil, err }