forked from webdevops/azure-metrics-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.go
51 lines (42 loc) · 1.05 KB
/
misc.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
package main
import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
)
func getPrometheusTimeout(r *http.Request, defaultTimeout float64) (timeout float64, err error) {
// If a timeout is configured via the Prometheus header, add it to the request.
if v := r.Header.Get("X-Prometheus-Scrape-Timeout-Seconds"); v != "" {
timeout, err = strconv.ParseFloat(v, 64)
if err != nil {
return
}
}
if timeout == 0 {
timeout = defaultTimeout
}
return
}
func paramsGetRequired(params url.Values, name string) (value string, err error) {
value = params.Get(name)
if value == "" {
err = fmt.Errorf("parameter \"%v\" is missing", name)
}
return
}
func paramsGetList(params url.Values, name string) (list []string, err error) {
for _, v := range params[name] {
list = append(list, strings.Split(v, ",")...)
}
return
}
func paramsGetListRequired(params url.Values, name string) (list []string, err error) {
list, err = paramsGetList(params, name)
if len(list) == 0 {
err = fmt.Errorf("parameter \"%v\" is missing", name)
return
}
return
}