-
Notifications
You must be signed in to change notification settings - Fork 313
/
common.go
72 lines (59 loc) · 1.57 KB
/
common.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
66
67
68
69
70
71
72
package main
import (
"errors"
"net/url"
"sort"
"time"
"github.com/goware/urlx"
)
const (
decBase = 10
rateLimitInterval = 10 * time.Millisecond
oneSecond = 1 * time.Second
exitFailure = 1
)
var (
version = "unspecified"
emptyConf = config{}
parser = newKingpinParser()
defaultTestDuration = 10 * time.Second
defaultNumberOfConns = uint64(125)
defaultTimeout = 2 * time.Second
httpMethods = []string{
"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS",
"PATCH",
}
cantHaveBody = []string{"HEAD"}
errUnsupportedScheme = errors.New("unsupported scheme")
errInvalidNumberOfConns = errors.New(
"invalid number of connections(must be > 0)")
errInvalidNumberOfRequests = errors.New(
"invalid number of requests(must be > 0)")
errInvalidTestDuration = errors.New(
"invalid test duration(must be >= 1s)")
errNegativeTimeout = errors.New(
"timeout can't be negative")
errBodyNotAllowed = errors.New(
"HEAD requests cannot have body")
errNoPathToCert = errors.New(
"no Path to TLS Client Certificate")
errNoPathToKey = errors.New(
"no Path to TLS Client Certificate Private Key")
errZeroRate = errors.New(
"rate can't be less than 1")
errBodyProvidedTwice = errors.New("use either --body or --body-file")
errInvalidHeaderFormat = errors.New("invalid header format")
errEmptyPrintSpec = errors.New(
"empty print spec is not a valid print spec")
)
func ParseURLOrPanic(s string) *url.URL {
u, err := urlx.Parse(s)
if err != nil {
panic(err)
}
return u
}
func init() {
sort.Strings(httpMethods)
sort.Strings(cantHaveBody)
}