forked from pwaller/jump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
45 lines (40 loc) · 959 Bytes
/
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
package main
import (
"crypto/tls"
"net/http"
"os"
"time"
)
func BreakArgsBySeparator() (left, right []string) {
seenSeparator := false
for _, param := range os.Args[1:] {
if param == "--" {
seenSeparator = true
continue
}
if seenSeparator {
right = append(right, param)
} else {
left = append(left, param)
}
}
return
}
// Configure HTTP for 1s timeout and HTTPS to ignore SSL CA errors.
// if `externalRequest` is true, sets it back to the go defaults, otherwise
// ensures that CA violations are treated as errors
func ConfigureHTTP(externalRequest bool) {
if externalRequest {
http.DefaultClient.Timeout = 0
t := http.DefaultTransport.(*http.Transport)
// Use the default TLS config
t.TLSClientConfig = nil
return
}
http.DefaultClient.Timeout = 1 * time.Second
t := http.DefaultTransport.(*http.Transport)
// Ignore SSL certificate errors
t.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}