This commit is contained in:
@@ -21,6 +21,10 @@ func Int64(dst *int64) encoding.TextUnmarshaler {
|
||||
return (*int64Text)(dst)
|
||||
}
|
||||
|
||||
func Float64(dst *float64) encoding.TextUnmarshaler {
|
||||
return (*float64Text)(dst)
|
||||
}
|
||||
|
||||
func Bool(dst *bool) encoding.TextUnmarshaler {
|
||||
return (*boolText)(dst)
|
||||
}
|
||||
@@ -33,6 +37,7 @@ type (
|
||||
rawText string
|
||||
intText int
|
||||
int64Text int64
|
||||
float64Text float64
|
||||
boolText bool
|
||||
platformText accounts.Platform
|
||||
)
|
||||
@@ -60,6 +65,15 @@ func (n *int64Text) UnmarshalText(text []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *float64Text) UnmarshalText(text []byte) error {
|
||||
i, err := strconv.ParseFloat(string(text), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*n = float64Text(i)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *boolText) UnmarshalText(text []byte) error {
|
||||
v, err := strconv.ParseBool(string(text))
|
||||
if err != nil {
|
||||
|
||||
@@ -65,7 +65,9 @@ func (s Spec) Unmarshal(c *gin.Context) error {
|
||||
for k, dst := range s.form {
|
||||
v, ok := c.GetPostForm(k)
|
||||
if !ok || v == "" {
|
||||
return response.BadRequest().Msgf("no %s provided", k)
|
||||
if v, ok = c.GetQuery(k); !ok {
|
||||
return response.BadRequest().Msgf("no %s provided", k)
|
||||
}
|
||||
}
|
||||
if err := dst.UnmarshalText([]byte(v)); err != nil {
|
||||
return response.BadRequest().Wrap(err).Msgf("invalid %s provided", k)
|
||||
|
||||
Reference in New Issue
Block a user