...
1
16
17 package clientcmd
18
19 import (
20 "fmt"
21 "net/url"
22 "strconv"
23 "time"
24 )
25
26
27
28 func ParseTimeout(duration string) (time.Duration, error) {
29 if i, err := strconv.ParseInt(duration, 10, 64); err == nil && i >= 0 {
30 return (time.Duration(i) * time.Second), nil
31 }
32 if requestTimeout, err := time.ParseDuration(duration); err == nil {
33 return requestTimeout, nil
34 }
35 return 0, fmt.Errorf("Invalid timeout value. Timeout must be a single integer in seconds, or an integer followed by a corresponding time unit (e.g. 1s | 2m | 3h)")
36 }
37
38 func parseProxyURL(proxyURL string) (*url.URL, error) {
39 u, err := url.Parse(proxyURL)
40 if err != nil {
41 return nil, fmt.Errorf("could not parse: %v", proxyURL)
42 }
43
44 switch u.Scheme {
45 case "http", "https", "socks5":
46 default:
47 return nil, fmt.Errorf("unsupported scheme %q, must be http, https, or socks5", u.Scheme)
48 }
49 return u, nil
50 }
51
View as plain text