mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
fced48d540
This can be done via extra_fields query arg or via VL-Extra-Fields HTTP header.
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7354#issuecomment-2448671445
(cherry picked from commit 4478e48eb6
)
24 lines
601 B
Go
24 lines
601 B
Go
package httputils
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// GetArray returns an array of comma-separated values from r with the argKey quey arg or with headerKey header.
|
|
func GetArray(r *http.Request, argKey, headerKey string) []string {
|
|
v := GetRequestValue(r, argKey, headerKey)
|
|
if v == "" {
|
|
return nil
|
|
}
|
|
return strings.Split(v, ",")
|
|
}
|
|
|
|
// GetRequestValue returns r value for the given argKey query arg or for the given headerKey header.
|
|
func GetRequestValue(r *http.Request, argKey, headerKey string) string {
|
|
v := r.FormValue(argKey)
|
|
if v == "" {
|
|
v = r.Header.Get(headerKey)
|
|
}
|
|
return v
|
|
}
|