|
@ -1,6 +1,7 @@ |
|
|
package rpc |
|
|
package rpc |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/hex" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"regexp" |
|
|
"regexp" |
|
|
"strconv" |
|
|
"strconv" |
|
@ -34,7 +35,12 @@ func GetParam(r *http.Request, param string) string { |
|
|
return s |
|
|
return s |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func GetParamInt64Safe(r *http.Request, param string) (int64, error) { |
|
|
|
|
|
|
|
|
func GetParamByteSlice(r *http.Request, param string) ([]byte, error) { |
|
|
|
|
|
s := GetParam(r, param) |
|
|
|
|
|
return hex.DecodeString(s) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetParamInt64(r *http.Request, param string) (int64, error) { |
|
|
s := GetParam(r, param) |
|
|
s := GetParam(r, param) |
|
|
i, err := strconv.ParseInt(s, 10, 64) |
|
|
i, err := strconv.ParseInt(s, 10, 64) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -42,15 +48,8 @@ func GetParamInt64Safe(r *http.Request, param string) (int64, error) { |
|
|
} |
|
|
} |
|
|
return i, nil |
|
|
return i, nil |
|
|
} |
|
|
} |
|
|
func GetParamInt64(r *http.Request, param string) int64 { |
|
|
|
|
|
i, err := GetParamInt64Safe(r, param) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panicAPI(err) |
|
|
|
|
|
} |
|
|
|
|
|
return i |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetParamInt32Safe(r *http.Request, param string) (int32, error) { |
|
|
|
|
|
|
|
|
func GetParamInt32(r *http.Request, param string) (int32, error) { |
|
|
s := GetParam(r, param) |
|
|
s := GetParam(r, param) |
|
|
i, err := strconv.ParseInt(s, 10, 32) |
|
|
i, err := strconv.ParseInt(s, 10, 32) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -58,15 +57,8 @@ func GetParamInt32Safe(r *http.Request, param string) (int32, error) { |
|
|
} |
|
|
} |
|
|
return int32(i), nil |
|
|
return int32(i), nil |
|
|
} |
|
|
} |
|
|
func GetParamInt32(r *http.Request, param string) int32 { |
|
|
|
|
|
i, err := GetParamInt32Safe(r, param) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panicAPI(err) |
|
|
|
|
|
} |
|
|
|
|
|
return i |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetParamUint64Safe(r *http.Request, param string) (uint64, error) { |
|
|
|
|
|
|
|
|
func GetParamUint64(r *http.Request, param string) (uint64, error) { |
|
|
s := GetParam(r, param) |
|
|
s := GetParam(r, param) |
|
|
i, err := strconv.ParseUint(s, 10, 64) |
|
|
i, err := strconv.ParseUint(s, 10, 64) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -74,30 +66,16 @@ func GetParamUint64Safe(r *http.Request, param string) (uint64, error) { |
|
|
} |
|
|
} |
|
|
return i, nil |
|
|
return i, nil |
|
|
} |
|
|
} |
|
|
func GetParamUint64(r *http.Request, param string) uint64 { |
|
|
|
|
|
i, err := GetParamUint64Safe(r, param) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panicAPI(err) |
|
|
|
|
|
} |
|
|
|
|
|
return i |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetParamRegexpSafe(r *http.Request, param string, re *regexp.Regexp) (string, error) { |
|
|
|
|
|
|
|
|
func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) { |
|
|
s := GetParam(r, param) |
|
|
s := GetParam(r, param) |
|
|
if !re.MatchString(s) { |
|
|
if !re.MatchString(s) { |
|
|
return "", Errorf(param, "Did not match regular expression %v", re.String()) |
|
|
return "", Errorf(param, "Did not match regular expression %v", re.String()) |
|
|
} |
|
|
} |
|
|
return s, nil |
|
|
return s, nil |
|
|
} |
|
|
} |
|
|
func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp, required bool) string { |
|
|
|
|
|
s, err := GetParamRegexpSafe(r, param, re) |
|
|
|
|
|
if (required || s != "") && err != nil { |
|
|
|
|
|
panicAPI(err) |
|
|
|
|
|
} |
|
|
|
|
|
return s |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetParamFloat64Safe(r *http.Request, param string) (float64, error) { |
|
|
|
|
|
|
|
|
func GetParamFloat64(r *http.Request, param string) (float64, error) { |
|
|
s := GetParam(r, param) |
|
|
s := GetParam(r, param) |
|
|
f, err := strconv.ParseFloat(s, 64) |
|
|
f, err := strconv.ParseFloat(s, 64) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -105,10 +83,3 @@ func GetParamFloat64Safe(r *http.Request, param string) (float64, error) { |
|
|
} |
|
|
} |
|
|
return f, nil |
|
|
return f, nil |
|
|
} |
|
|
} |
|
|
func GetParamFloat64(r *http.Request, param string) float64 { |
|
|
|
|
|
f, err := GetParamFloat64Safe(r, param) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panicAPI(err) |
|
|
|
|
|
} |
|
|
|
|
|
return f |
|
|
|
|
|
} |
|
|
|