-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
52 lines (39 loc) · 1.06 KB
/
info.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
51
52
// 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"
"errors"
"io/ioutil"
"net/http"
)
// Version returns information about the API; currently name, hostname, sw_version and api_version
func (c *AuthClient) Version() (map[string]interface{}, error) {
var result map[string]interface{}
client := http.Client{}
request, err := http.NewRequest("GET", c.getUrl("/api/v1/info/version"), nil)
if err != nil {
return result, err
}
request.Header.Add("authorization", "Session "+c.SessionId)
response, err := client.Do(request)
if err != nil {
return result, err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return result, err
}
defer response.Body.Close()
var jsonResult interface{}
err = json.Unmarshal(body, &jsonResult)
if err != nil {
return result, err
}
m, mOk := jsonResult.(map[string]interface{})
if mOk {
return m, nil
}
return result, errors.New("could not read response")
}