-
Notifications
You must be signed in to change notification settings - Fork 1
/
modules.go
50 lines (38 loc) · 1.05 KB
/
modules.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2022 Ralf Geschke. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package golrackpi
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// ModuleData specifies the structure of the response returned by a request to the "modules" endpoint
type ModuleData struct {
Id string `json:"id"`
Type string `json:"type"`
}
// Modules returns a list of modules with their type
func (c *AuthClient) Modules() ([]ModuleData, error) {
moduleData := []ModuleData{}
client := http.Client{}
request, err := http.NewRequest("GET", c.getUrl("/api/v1/modules"), nil)
if err != nil {
return moduleData, err
}
request.Header.Add("authorization", "Session "+c.SessionId)
response, err := client.Do(request)
if err != nil {
return moduleData, err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return moduleData, err
}
err = json.Unmarshal(body, &moduleData)
if err != nil {
return moduleData, err
}
return moduleData, nil
}