Skip to content

Commit

Permalink
Update to restate 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Jul 6, 2024
1 parent e47b3f6 commit a028c6e
Show file tree
Hide file tree
Showing 27 changed files with 2,096 additions and 3,232 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[![Go Reference](https://pkg.go.dev/badge/github.com/restatedev/sdk-go.svg)](https://pkg.go.dev/github.com/restatedev/sdk-go)
[![Go](https://github.com/restatedev/sdk-go/actions/workflows/test.yaml/badge.svg)](https://github.com/restatedev/sdk-go/actions/workflows/test.yaml)

> This only works with Restate version 0.8
# Restate Go SDK

[Restate](https://restate.dev/) is a system for easily building resilient applications using *distributed durable async/await*. This repository contains the Restate SDK for writing services in **Golang**.
Expand Down
2 changes: 0 additions & 2 deletions proto/buf.yaml → buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
version: v1
deps:
- buf.build/restatedev/proto
breaking:
use:
- FILE
Expand Down
16 changes: 8 additions & 8 deletions example/user_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"slices"
"time"

"github.com/restatedev/sdk-go"
restate "github.com/restatedev/sdk-go"
"github.com/rs/zerolog/log"
)

func addTicket(ctx restate.Context, userId, ticketId string) (bool, error) {

var success bool
if err := ctx.Service(TicketServiceName).Method("reserve").Do(ticketId, userId, &success); err != nil {
if err := ctx.Object(TicketServiceName, ticketId).Method("reserve").Do(userId, &success); err != nil {
return false, err
}

Expand All @@ -33,7 +33,7 @@ func addTicket(ctx restate.Context, userId, ticketId string) (bool, error) {
return false, err
}

if err := ctx.Service(UserSessionServiceName).Method("expireTicket").Send(userId, ticketId, 15*time.Minute); err != nil {
if err := ctx.Object(UserSessionServiceName, ticketId).Method("expireTicket").Send(ticketId, 15*time.Minute); err != nil {
return false, err
}

Expand Down Expand Up @@ -62,7 +62,7 @@ func expireTicket(ctx restate.Context, _, ticketId string) (void restate.Void, e
return void, err
}

return void, ctx.Service(TicketServiceName).Method("unreserve").Send(ticketId, nil, 0)
return void, ctx.Object(TicketServiceName, ticketId).Method("unreserve").Send(nil, 0)
}

func checkout(ctx restate.Context, userId string, _ restate.Void) (bool, error) {
Expand All @@ -78,17 +78,17 @@ func checkout(ctx restate.Context, userId string, _ restate.Void) (bool, error)
}

var response PaymentResponse
if err := ctx.Service(CheckoutServiceName).
if err := ctx.Object(CheckoutServiceName, "").
Method("checkout").
Do("", PaymentRequest{UserID: userId, Tickets: tickets}, &response); err != nil {
Do(PaymentRequest{UserID: userId, Tickets: tickets}, &response); err != nil {
return false, err
}

log.Info().Str("id", response.ID).Int("price", response.Price).Msg("payment details")

call := ctx.Service(TicketServiceName).Method("markAsSold")
for _, ticket := range tickets {
if err := call.Send(ticket, nil, 0); err != nil {
call := ctx.Object(ticket, TicketServiceName).Method("markAsSold")
if err := call.Send(nil, 0); err != nil {
return false, err
}
}
Expand Down
288 changes: 55 additions & 233 deletions generated/proto/discovery/discovery.pb.go

Large diffs are not rendered by default.

Loading

0 comments on commit a028c6e

Please sign in to comment.