VictoriaMetrics/lib/httputils/bool.go
Aliaksandr Valialkin 427ce69426
app/vmselect: move common http functionality from app/vmselect/searchutils to lib/httputils
While at it, move app/vmselect/bufferedwriter to lib/bufferedwriter, since it is going to be used in VictoriaLogs
2023-07-06 17:22:23 -07:00

34 lines
836 B
Go

package httputils
import (
"flag"
"net/http"
"strings"
)
var (
denyPartialResponse = flag.Bool("search.denyPartialResponse", false, "Whether to deny partial responses if a part of -storageNode instances fail to perform queries; "+
"this trades availability over consistency; see also -search.maxQueryDuration")
)
// GetBool returns boolean value from the given argKey query arg.
func GetBool(r *http.Request, argKey string) bool {
argValue := r.FormValue(argKey)
switch strings.ToLower(argValue) {
case "", "0", "f", "false", "no":
return false
default:
return true
}
}
// GetDenyPartialResponse returns whether partial responses are denied.
func GetDenyPartialResponse(r *http.Request) bool {
if *denyPartialResponse {
return true
}
if r == nil {
return false
}
return GetBool(r, "deny_partial_response")
}