package request

import (
	"net/http"
	"strconv"
)

// RequestString get string value from url, if not, get from post form.
func RequestString(r *http.Request, key string) string {
	var val string
	val = r.FormValue(key)
	if len(val) > 0 {
		return val
	}

	val = r.PostFormValue(key)
	return val
}

// RequestFormInt get int value from url, if not, get from post form.
func RequestFormInt(r *http.Request, key string) int {
	var val int
	val, _ = strconv.Atoi(r.FormValue(key))
	return val
}

// RequestPostFromInt get int value from url, if not, get from post form.
func RequestPostFromInt(r *http.Request, key string) int {
	var val int
	val, _ = strconv.Atoi(r.PostFormValue(key))
	return val
}

// RequestFormFloat get float val from url, if not, get from post form.
func RequestFormFloat(r *http.Request, key string) float64 {
	var val float64
	val, _ = strconv.ParseFloat(r.FormValue(key), 64)
	return val
}

// RequestPostFormFloat get float val from url, if not, get from post form.
func RequestPostFormFloat(r *http.Request, key string) float64 {
	var val float64
	val, _ = strconv.ParseFloat(r.PostFormValue(key), 64)
	return val
}