-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for int, float, and bool on ingress #905
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
2d30d48
to
56d77bf
Compare
@@ -127,4 +127,34 @@ class Echo { | |||
body = req.body | |||
) | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too!
if err := json.Unmarshal(body, &responseInt); err != nil { | ||
return nil, fmt.Errorf("HTTP response body is not valid int: %w", err) | ||
} | ||
return []byte(fmt.Sprintf("%d", responseInt)), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use the strconv
package rather than Sprintf
for these values here and below.
strconv.Itoa()
, strconv.FormatBool()
, though strconv.FormatFloat()
might be too annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strconv.FormatFloat(responseFloat, 'f', -1, 64
yeah this format is crazy! :)
return nil, err | ||
} | ||
|
||
floatVal, err := strconv.ParseFloat(string(bodyData), 64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use ParseFloat for integers, it loses precision.
56d77bf
to
9948438
Compare
case *schema.Int: | ||
var responseInt int | ||
if err := json.Unmarshal(body, &responseInt); err != nil { | ||
return nil, fmt.Errorf("HTTP response body is not valid int: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"not a valid"
9948438
to
8e3d771
Compare
Some
go
examples: