-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
utils.go
57 lines (45 loc) · 1.26 KB
/
utils.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
package faker
import (
"net/http"
"os"
"runtime"
)
const (
maxRetries = 7
)
// HTTPClient does HTTP requests to remote servers
type HTTPClient interface {
Get(url string) (resp *http.Response, err error)
}
// HTTPClientImpl is the default implementation of HTTPClient
type HTTPClientImpl struct{}
// Get do a GET request and returns a *http.Response
func (HTTPClientImpl) Get(url string) (resp *http.Response, err error) {
for i := 0; i < maxRetries; i++ {
resp, err = http.Get(url)
if err == nil {
return resp, nil
}
}
return resp, err
}
// TempFileCreator creates temporary files
type TempFileCreator interface {
TempFile(prefix string) (f *os.File, err error)
}
// TempFileCreatorImpl is the default implementation of TempFileCreator
type TempFileCreatorImpl struct{}
// TempFile creates a temporary file
func (TempFileCreatorImpl) TempFile(prefix string) (f *os.File, err error) {
return os.CreateTemp(os.TempDir(), prefix)
}
// OSResolver returns the GOOS value for operating an operating system
type OSResolver interface {
OS() string
}
// OSResolverImpl is the default implementation of OSResolver
type OSResolverImpl struct{}
// OS returns the runtime.GOOS value for the host operating system
func (OSResolverImpl) OS() string {
return runtime.GOOS
}