mirror of https://github.com/dapr/docs.git
Fixed Go sample code (#2531)
Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
parent
0cbc5b3294
commit
5a69a5c87e
|
@ -210,38 +210,39 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```go
|
```go
|
||||||
//dependencies
|
// dependencies
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
dapr "github.com/dapr/go-sdk/client"
|
dapr "github.com/dapr/go-sdk/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
//code
|
// code
|
||||||
func main() {
|
func main() {
|
||||||
|
const STATE_STORE_NAME = "statestore"
|
||||||
|
rand.Seed(time.Now().UnixMicro())
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
time.Sleep(5000)
|
|
||||||
orderId := rand.Intn(1000-1) + 1
|
orderId := rand.Intn(1000-1) + 1
|
||||||
client, err := dapr.NewClient()
|
client, err := dapr.NewClient()
|
||||||
STATE_STORE_NAME := "statestore"
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
//Using Dapr SDK to save and get state
|
err = client.SaveState(ctx, STATE_STORE_NAME, "order_1", []byte(strconv.Itoa(orderId)), nil)
|
||||||
if err := client.SaveState(ctx, STATE_STORE_NAME, "order_1", []byte(strconv.Itoa(orderId))); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
result, err := client.GetState(ctx, STATE_STORE_NAME, "order_2")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("Result after get: ")
|
result, err := client.GetState(ctx, STATE_STORE_NAME, "order_1", nil)
|
||||||
log.Println(result)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Println("Result after get:", string(result.Value))
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue