Skip to content
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

[State] Add missing Go examples #4127

Merged
merged 7 commits into from
May 20, 2024
Merged

Conversation

hhunter-ms
Copy link
Collaborator

Description

Add examples for Bulk State and StateStore transactions for Go

Issue reference

PR will close: #4059

Signed-off-by: Hannah Hunter <[email protected]>
@hhunter-ms hhunter-ms self-assigned this May 2, 2024
@hhunter-ms hhunter-ms requested review from a team as code owners May 2, 2024 19:49
@hhunter-ms hhunter-ms requested a review from salaboy May 2, 2024 19:49
Copy link
Contributor

@salaboy salaboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've checked the code and made a few suggestions.

keys := []string{"key1", "key2", "key3"}
items, err := client.GetBulkState(ctx, store, keys, nil, 100)

log.Println("Result after get:", string(result.Value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work, as this is an array of BulkStateItems, what's the objective of this println? show all the Items in the array? We might need to loop here.

Copy link
Collaborator Author

@hhunter-ms hhunter-ms May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salaboy I'm least familiar with Go, so I'm not sure about the printIn haha I may have grabbed it when piecing together examples

Copy link
Member

@msfussell msfussell May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salaboy
Yes, @hhunter-ms is asking the the equivalent of this below, but for bulkstate, which means iterating over each item and showing it's value. This is just for a simple example to show how the API works

		result, err := client.GetState(ctx, STATE_STORE_NAME, "order_1", nil)
		if err != nil {
			panic(err)
		}
		log.Println("Result after get:", string(result.Value))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then @hhunter-ms something like this would work

                 items, err := client.GetBulkState(ctx, STATE_STORE_NAME, keys, nil, 100)
		if err != nil {
			panic(err)
		}
		for _, item := range items {
			log.Println("Item from GetBulkState:", string(item.Value))
		}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @salaboy! I've pushed that update

Copy link

Stale PR, paging all reviewers

Copy link
Contributor

@marcduiker marcduiker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hhunter-ms hhunter-ms merged commit b23f976 into dapr:v1.13 May 20, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StateStore transactions is not displayed using Go
4 participants