-
Notifications
You must be signed in to change notification settings - Fork 53
feat: add go snippets #735
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
Conversation
✅ Deploy Preview for openpayments-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- uses new in-lined, non-snippet pattern
| <TabItem label='Go' icon='seti:go'> | ||
|
|
||
| ```go wrap | ||
| combinedQuoteAmount := "10000" // merchantQuote.DebitAmount.Value + platformQuote.DebitAmount.Value |
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.
This deviates from the TS/Rust version but I felt like this was clearer than parsing/summing the previous values.
Also, is the ts version correct?
const combinedQuoteAmount = quote1.debitAmount.value + // '9900'
quote2.debitAmount.value // '100'Not sure if these are strings or big ints. Client might convert them to big ints. Or it might resolve to '9900100'.
This is how it might look (similar to Rust) if it actually parses correctly (but I thought what I had is sufficient):
merchantValue, err := strconv.ParseInt(merchantQuote.DebitAmount.Value, 10, 64)
if err != nil {
log.Fatalf("invalid merchant amount: %v", err)
}
platformValue, err := strconv.ParseInt(platformQuote.DebitAmount.Value, 10, 64)
if err != nil {
log.Fatalf("invalid platform amount: %v", err)
}
combinedQuoteAmount := strconv.FormatInt(merchantValue+platformValue, 10)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.
Good catch. I think the TS version would just concatenate the strings. We can go with the method you presented since it's more obvious.
Can you also please update the TS one to be just
combinedQuoteAmount = '1000' // 9900 + 100
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.
or are they actually bigints? Anyways, I think combinedQuoteAmount = '10000' // 9900 + 100 is clearer. changed to that.
Co-authored-by: Melissa Henderson <[email protected]>
Co-authored-by: Melissa Henderson <[email protected]>
| if err := outgoingPayload.FromCreateOutgoingPaymentWithQuote(rs.CreateOutgoingPaymentWithQuote{ | ||
| WalletAddressSchema: *customerWalletAddress.Id, | ||
| QuoteId: *customerQuote.Id, | ||
| }); err != 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.
| }); err != nil { | |
| }); if err != 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.
Happens in a few guides other guides, just needs a find+replace
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.
}); if err != nil { is a syntax error: syntax error: unexpected keyword if, expected expression
can check out this example: https://go.dev/play/p/BPjtuPgQ-AO. If you replace it with the original }); err != nil { you should see that it works.
So I think it's fine as-is but to keep with your direction, it could be un-compacted a bit to this:
err := outgoingPayload.FromCreateOutgoingPaymentWithQuote(
CreateOutgoingPaymentWithQuote{
WalletAddressSchema: *customerWalletAddress.Id,
QuoteId: *customerQuote.Id,
},
)
if err != nil {
log.Fatalf("Error creating payload: %v\n", err)
}| senderOutgoingPaymentGrant, err := client.Grant.Continue(context.TODO(), op.GrantContinueParams{ | ||
| URL: pendingSenderOutgoingPaymentGrant.Continue.Uri, | ||
| AccessToken: pendingSenderOutgoingPaymentGrant.Continue.AccessToken.Value, | ||
| InteractRef: INTERACT_REF, | ||
| }) |
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.
minor, on the preview link, InteractRef: INTERACT_REF, is indented differently than URL AccessToken
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.
fixed
| <TabItem label='Go' icon='seti:go'> | ||
| ```go wrap |
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.
This page's snippets have an extra starting indent
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.
fixed
| AssetCode: "CAD", | ||
| AssetScale: 2, | ||
| }, | ||
| }); err != 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.
| }); err != nil { | |
| }); if err != nil { |
| Limits: &limits, | ||
| } | ||
| outgoingAccessItem := as.AccessItem{} | ||
| if err := outgoingAccessItem.FromAccessOutgoing(outgoingAccess); err != 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.
| if err := outgoingAccessItem.FromAccessOutgoing(outgoingAccess); err != nil { | |
| if err := outgoingAccessItem.FromAccessOutgoing(outgoingAccess); if err != nil { |
| <TabItem label='Go' icon='seti:go'> | ||
|
|
||
| ```go wrap | ||
| combinedQuoteAmount := "10000" // merchantQuote.DebitAmount.Value + platformQuote.DebitAmount.Value |
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.
Good catch. I think the TS version would just concatenate the strings. We can go with the method you presented since it's more obvious.
Can you also please update the TS one to be just
combinedQuoteAmount = '1000' // 9900 + 100
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.
Let's not update the spec version yet (since we don't want to show grant spent amounts API being available before have the docs for the grant spent amount feature).
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 dont remember exactly what commit we were on before, and I didn't figure out a clean way to revert, so I changed it to the previous commit (41ea94b (tag: v1.1.1) fix: resource server signature spec (#21)) which I think should be fine (and possibly what it was before).
Co-authored-by: Max Kurapov <[email protected]>
Description of changes
Adds docs/snippets for go sdk
I had to wrestled with prettier quite a bit but I think its all cleaned up.
fixes #741
Required
Conditional