-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.go
52 lines (39 loc) · 1.09 KB
/
string.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
package rfc8288
import (
"fmt"
"strings"
)
// String returns the Link in a format usable for HTTP Headers as defined by RFC8288
func (l Link) String() string {
var result []string
result = append(result, fmt.Sprintf(`<%s>`, l.HREF.String()))
if l.Rel != "" {
result = append(result, fmt.Sprintf(`rel="%s"`, l.Rel))
}
if l.Rev != "" {
result = append(result, fmt.Sprintf(`rev="%s"`, l.Rev))
}
if l.Anchor != "" {
result = append(result, fmt.Sprintf(`anchor="%s"`, l.Anchor))
}
if l.HREFLang != "" {
result = append(result, fmt.Sprintf(`hreflang="%s"`, l.HREFLang))
}
if l.Media != "" {
result = append(result, fmt.Sprintf(`media="%s"`, l.Media))
}
if l.Title != "" {
result = append(result, fmt.Sprintf(`title="%s"`, l.Title))
}
if l.TitleStar != "" {
result = append(result, fmt.Sprintf(`title*="%s"`, l.TitleStar))
}
if l.Type != "" {
result = append(result, fmt.Sprintf(`type="%s"`, l.Type))
}
for _, key := range l.extensionKeys {
value := l.extensions[key]
result = append(result, fmt.Sprintf(`%s="%s"`, key, value))
}
return strings.Join(result, "; ")
}