generated from WillAbides/goproject-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
internal.go
40 lines (34 loc) · 820 Bytes
/
internal.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
package internal
import (
"net/http"
"regexp"
)
// EndpointAttribute is an attribute for an endpoint
type EndpointAttribute int
var relLinkExp = regexp.MustCompile(`<(.+?)>\s*;\s*rel="([^"]*)"`)
// RelLink returns the content of lnk from the response's Link header or "" if it does not exist
func RelLink(resp *http.Response, lnk string) string {
for _, link := range resp.Header.Values("Link") {
for _, match := range relLinkExp.FindAllStringSubmatch(link, -1) {
if match[2] == lnk {
return match[1]
}
}
}
return ""
}
// String returns a pointer to s
func String(s string) *string {
return &s
}
func isRedirectOnly(validStatuses []int) bool {
if len(validStatuses) == 0 {
return false
}
for _, vs := range validStatuses {
if vs < 300 || vs > 399 {
return false
}
}
return true
}