mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 08:36:55 +03:00
21 lines
402 B
Go
21 lines
402 B
Go
package httputil
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// GetInt returns integer value from the given argKey.
|
|
func GetInt(r *http.Request, argKey string) (int, error) {
|
|
argValue := r.FormValue(argKey)
|
|
if len(argValue) == 0 {
|
|
return 0, nil
|
|
}
|
|
n, err := strconv.Atoi(argValue)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("cannot parse integer %q=%q: %w", argKey, argValue, err)
|
|
}
|
|
return n, nil
|
|
}
|