upd(all): parse uint64 from post arrays
This commit is contained in:
@@ -76,6 +76,7 @@ usort($apis, function($a, $b) {
|
||||
|
||||
$parsers = array(
|
||||
"uint64" => "parseUInt64",
|
||||
"[]uint64" => "parseUInt64A",
|
||||
"int" => "parseInt",
|
||||
"bool" => "parseBool",
|
||||
"types.JSONText" => "parseJSONText",
|
||||
|
||||
@@ -63,6 +63,8 @@ func ({self} *{name|expose}{call.name|capitalize}) Fill(r *http.Request) (err er
|
||||
{foreach $params as $param}
|
||||
{if strtolower($method) === "path"}
|
||||
{self}.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}({/if}chi.URLParam(r, "{param.name}"){if ($param.type !== "string")}){/if}
|
||||
{elseif substr($param.type, 0, 2) === '[]' && isset($parsers[$param.type])}
|
||||
{self}.{param.name|expose} = {$parsers[$param.type]}({if $method === "post"}r.Form["{param.name}"]{else}urlQuery["{param.name}"]{/if})
|
||||
{elseif $param.type === "*multipart.FileHeader"}
|
||||
if _, {self}.{param.name|expose}, err = r.FormFile("{$param.name}"); err != nil {
|
||||
return errors.Wrap(err, "error procesing uploaded file")
|
||||
|
||||
@@ -305,6 +305,7 @@ func (p *PageReorder) Fill(r *http.Request) (err error) {
|
||||
}
|
||||
|
||||
p.SelfID = parseUInt64(chi.URLParam(r, "selfID"))
|
||||
p.PageIDs = parseUInt64A(r.Form["pageIDs"])
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func parseInt(s string) int {
|
||||
return i
|
||||
}
|
||||
|
||||
// parseInt64 parses an string to int64
|
||||
// parseInt64 parses a string to int64
|
||||
func parseInt64(s string) int64 {
|
||||
if s == "" {
|
||||
return 0
|
||||
@@ -35,7 +35,7 @@ func parseInt64(s string) int64 {
|
||||
return i
|
||||
}
|
||||
|
||||
// parseUInt64 parses an string to uint64
|
||||
// parseUInt64 parses a string to uint64
|
||||
func parseUInt64(s string) uint64 {
|
||||
if s == "" {
|
||||
return 0
|
||||
@@ -44,7 +44,17 @@ func parseUInt64(s string) uint64 {
|
||||
return i
|
||||
}
|
||||
|
||||
// parseUInt64 parses an string to uint64
|
||||
func parseUInt64A(values []string) []uint64 {
|
||||
var result []uint64
|
||||
if values != nil && len(values) > 0 {
|
||||
for _, val := range values {
|
||||
result = append(result, parseUInt64(val))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// parseUInt64 parses a string to uint64
|
||||
func parseBool(s string) bool {
|
||||
return truthy.MatchString(strings.ToLower(s))
|
||||
}
|
||||
|
||||
@@ -458,6 +458,7 @@ func (c *ChannelInvite) Fill(r *http.Request) (err error) {
|
||||
}
|
||||
|
||||
c.ChannelID = parseUInt64(chi.URLParam(r, "channelID"))
|
||||
c.UserID = parseUInt64A(r.Form["userID"])
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ func (t *TeamCreate) Fill(r *http.Request) (err error) {
|
||||
|
||||
t.Name = val
|
||||
}
|
||||
t.Members = parseUInt64A(r.Form["members"])
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -166,6 +167,7 @@ func (t *TeamEdit) Fill(r *http.Request) (err error) {
|
||||
|
||||
t.Name = val
|
||||
}
|
||||
t.Members = parseUInt64A(r.Form["members"])
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,17 +17,25 @@ func parseJSONText(s string) (types.JSONText, error) {
|
||||
return *result, err
|
||||
}
|
||||
|
||||
// parseInt64 parses an string to int64
|
||||
// parseInt parses a string to int
|
||||
func parseInt(s string) int {
|
||||
if s == "" {
|
||||
return 0
|
||||
}
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
}
|
||||
|
||||
// parseInt64 parses a string to int64
|
||||
func parseInt64(s string) int64 {
|
||||
if s == "" {
|
||||
return 0
|
||||
}
|
||||
i, _ := strconv.ParseInt(s, 10, 64)
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
// parseUInt64 parses an string to uint64
|
||||
// parseUInt64 parses a string to uint64
|
||||
func parseUInt64(s string) uint64 {
|
||||
if s == "" {
|
||||
return 0
|
||||
@@ -36,7 +44,17 @@ func parseUInt64(s string) uint64 {
|
||||
return i
|
||||
}
|
||||
|
||||
// parseUInt64 parses an string to uint64
|
||||
func parseUInt64A(values []string) []uint64 {
|
||||
var result []uint64
|
||||
if values != nil && len(values) > 0 {
|
||||
for _, val := range values {
|
||||
result = append(result, parseUInt64(val))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// parseUInt64 parses a string to uint64
|
||||
func parseBool(s string) bool {
|
||||
return truthy.MatchString(strings.ToLower(s))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user