-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.go
44 lines (37 loc) · 1.04 KB
/
link.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
package abiquo_api
import (
"fmt"
"net/url"
"strings"
"github.com/go-resty/resty"
)
type Link struct {
Type string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Title string `json:"title,omitempty"`
Rel string `json:"rel,omitempty"`
// Oh my...
DiskController string `json:"diskController,omitempty"`
DiskControllerType string `json:"diskControllerType,omitempty"`
DiskLabel string `json:"diskLabel,omitempty"`
Length string `json:"length,omitempty"`
}
func (l *Link) Get(c *AbiquoClient) (*resty.Response, error) {
resp, err := c.checkResponse(c.client.R().SetHeader("Accept", l.Type).Get(l.Href))
return resp, err
}
func (l *Link) trimPort() {
r, _ := url.Parse(l.Href)
var trimport bool
if r.Scheme == "https" && r.Port() == "443" {
trimport = true
} else if r.Scheme == "http" && r.Port() == "80" {
trimport = true
} else {
trimport = false
}
if trimport {
l.Href = fmt.Sprintf("%s://%s%s?%s", r.Scheme, r.Hostname(), r.Path, r.RawQuery)
l.Href = strings.Trim(l.Href, "?")
}
}