The API doc examples seem to have some recurring e...
# golang
p
The API doc examples seem to have some recurring errors. I'm not 100% sure about this, since I'm very new to GoLang, programming in general and Pulumi, but I've discovered the following (see thread) ⬇️
https://www.pulumi.com/registry/packages/aws/api-docs/apigatewayv2/api/
Copy code
_, err := apigatewayv2.NewApi(ctx, "example", &apigatewayv2.ApiArgs{
should be
Copy code
_, err = apigatewayv2.NewApi(ctx, "example", &apigatewayv2.ApiArgs{
without the colon before the equals sign because the first variable is not defined • https://www.pulumi.com/registry/packages/aws/api-docs/apigatewayv2/route/
Copy code
_, err = apigatewayv2.NewRoute(ctx, "exampleRoute", &apigatewayv2.RouteArgs{
here it seems correct This type of error, where
_
is used as a placeholder (?) and the definition uses
:=
seems to be very common.
s
This may just be a Golang thing (I don’t know enough about your code). But if you create a couple of resources where you are “throwing away” one of the values (like
_, err := blah
and then later
_, err := otherblah
, it will flag the second one as incorrect (because you aren’t defining any new variables. That’s why you have to use
_, err = otherblah
. I probably didn’t do a great job of explaining this, but hopefully it helps a little!
e
_, err = ...
is a compile error if the
err
variable hasn't been declared elsewhere.
_ err := ...
is a compile error if the
err
variable is declared elsewhere. So our code generator has to change which one it uses based on if any other uses of
err
have happened before.