-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.go
29 lines (24 loc) · 836 Bytes
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package netgear_nighthawk_m5_api
import (
"encoding/json"
"fmt"
"github.com/silvercory/netgear_nighthawk_m5_api/models"
"net/http"
)
// ModelInfo is a general information request
func (n *NetgearNighthawkM5Api) ModelInfo() (models.ModelInfo, error) {
req, err := http.NewRequest(http.MethodGet, n.routerBaseURL+"/api/model.json?internalapi=1&x="+randomString(5), nil)
if err != nil {
return models.ModelInfo{}, fmt.Errorf("failed to create request: %w", err)
}
resp, err := n.httpClient.Do(req)
if err != nil {
return models.ModelInfo{}, fmt.Errorf("failed to send request: %w", err)
}
defer resp.Body.Close()
var response models.ModelInfo
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return models.ModelInfo{}, fmt.Errorf("failed to decode response: %w", err)
}
return response, nil
}