-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
65 lines (53 loc) · 1.04 KB
/
util.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package awsmocker
import (
"bufio"
"encoding/json"
"encoding/xml"
"errors"
"io"
"strings"
)
// var awsDomainRegexp = regexp.MustCompile(`(amazonaws\.com|\.aws)$`)
func encodeAsXml(obj any) string {
out, err := xml.MarshalIndent(obj, "", " ")
if err != nil {
panic(err)
}
return string(out)
}
func EncodeAsJson(obj any) string {
out, err := json.Marshal(obj)
if err != nil {
panic(err)
}
return string(out)
}
func inferContentType(value string) string {
switch {
case strings.HasPrefix(value, "<"):
return ContentTypeXML
case strings.HasPrefix(value, "{"):
return ContentTypeJSON
default:
return ContentTypeText
}
}
func isEof(r *bufio.Reader) bool {
_, err := r.Peek(1)
return errors.Is(err, io.EOF)
}
/*
// whether this is an AWS hostname that should be handled
func isAwsHostname(hostname string) bool {
if strings.HasSuffix(hostname, "amazonaws.com") {
return true
}
if strings.HasSuffix(hostname, "aws") {
return true
}
if strings.HasSuffix(hostname, "amazonaws.com.cn") {
return true
}
return false
}
*/