2023-06-21 05:02:46 +02:00
|
|
|
package httputils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-11-01 20:06:15 +01:00
|
|
|
// 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)
|
2023-06-21 05:02:46 +02:00
|
|
|
if v == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return strings.Split(v, ",")
|
|
|
|
}
|
2024-11-01 20:06:15 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|