Categorygithub.com/restatedev/sdk-go
modulepackage
0.13.2
Repository: https://github.com/restatedev/sdk-go.git
Documentation: pkg.go.dev

# README

Go Reference Go

Restate Go SDK

Restate is a system for easily building resilient applications using distributed durable async/await. This repository contains the Restate SDK for writing services in Golang.

Community

Examples

This repo contains an example based on the Ticket Reservation Service.

You can also check a list of examples available here: https://github.com/restatedev/examples?tab=readme-ov-file#go

How to use the example

Download and run restate, as described here v1.x

restate-server

In another terminal run the example

cd restate-sdk-go/example
go run .

In a third terminal register:

restate deployments register http://localhost:9080

And do the following steps

  • Add tickets to basket
curl -v localhost:8080/UserSession/azmy/AddTicket \
    -H 'content-type: application/json' \
    -d '"ticket-1"'

# true
curl -v localhost:8080/UserSession/azmy/AddTicket \
    -H 'content-type: application/json' \
    -d '"ticket-2"'
# true

Trying adding the same tickets again should return false since they are already reserved. If you didn't check out the tickets in 15min (if you are impatient change the delay in code to make it shorter)

  • Check out
curl localhost:8080/UserSession/azmy/Checkout
# true

Versions

This library follows Semantic Versioning.

The compatibility with Restate is described in the following table:

Restate Server\sdk-go0.9/0.10/0.11
1.0βœ…
1.1βœ…

Contributing

We’re excited if you join the Restate community and start contributing! Whether it is feature requests, bug reports, ideas & feedback or PRs, we appreciate any and all contributions. We know that your time is precious and, therefore, deeply value any effort to contribute!

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
protoc-gen-go-restate is a plugin for the Google protocol buffer compiler to generate Restate servers and clients.
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

After is an alternative to [Sleep] which allows you to complete other tasks concurrently with the sleep.
Awakeable returns a Restate awakeable; a 'promise' to a future value or error, that can be resolved or rejected by other services.
Clear deletes a key.
ClearAll drops all stored state associated with this Object key.
ErrorCode returns [Code] associated with error, defaulting to 500.
Get gets the value for a key.
IsTerminalError checks if err is terminal - ie, that returning it in a handler or Run function will finish the invocation with the error as a result.
Key retrieves the key for this virtual object invocation.
If the invocation was cancelled while obtaining the state (only possible if eager state is disabled), a cancellation error is returned.
NewObject creates a new named Virtual Object.
NewObjectHandler converts a function of signature [ObjectHandlerFn] into an exclusive-mode handler on a Virtual Object.
NewObjectSharedHandler converts a function of signature [ObjectSharedHandlerFn] into a shared-mode handler on a Virtual Object.
NewService creates a new named Service.
NewServiceHandler converts a function of signature [ServiceHandlerFn] into a handler on a Restate service.
NewWorkflow creates a new named Workflow.
NewWorkflowHandler converts a function of signature [WorkflowHandlerFn] into the 'Run' handler on a Workflow.
NewWorkflowSharedHandler converts a function of signature [ObjectSharedHandlerFn] into a shared-mode handler on a Workflow.
Object gets an Object request client by service name, key and method name.
ObjectSend gets an Object send client by service name, key and method name.
Promise returns a named Restate durable Promise that can be resolved or rejected during the workflow execution.
Rand returns a random source which will give deterministic results for a given invocation The source wraps the stdlib rand.Rand but with some extra helper methods This source is not safe for use inside .Run().
Reflect converts a struct with methods into a service definition where each correctly-typed and exported method of the struct will become a handler in the definition.
ResolveAwakeable allows an awakeable (not necessarily from this service) to be rejected with a particular error.
ResolveAwakeable allows an awakeable (not necessarily from this service) to be resolved with a particular value.
Run runs the function (fn), storing final results (including terminal errors) durably in the journal, or otherwise for transient errors stopping execution so Restate can retry the invocation.
No description provided by the author
Service gets a Service request client by service and method name.
Service gets a Service send client by service and method name.
Set sets a value against a key, using the provided codec (defaults to JSON).
Sleep for the duration d.
TerminalError returns a terminal error with optional code.
TerminalErrorf is a shorthand for combining fmt.Errorf with TerminalError.
WithCodec is an option that can be provided to many different functions that perform (de)serialisation in order to specify a custom codec with which to (de)serialise instead of the default of JSON.
WithDelay is an [SendOption] to specify the duration to delay the request.
WithErrorCode returns an error with specific [Code] attached.
WithHeaders is an option to specify outgoing headers when making a call.
WithPayloadCodec is an option that can be provided to handler/service options in order to specify a custom [encoding.PayloadCodec] with which to (de)serialise and set content-types instead of the default of JSON.
WithRequestType is primarily intended to be called from generated code, to provide type safety of input types.
Workflow gets a Workflow request client by service name, workflow ID and method name.
WorkflowSend gets a Workflow send client by service name, workflow ID and method name.

# Variables

WithBinary is an option to specify the use of [encoding.BinaryCodec] for (de)serialisation.
WithJSON is an option to specify the use of [encoding.JsonCodec] for (de)serialisation.
WithProto is an option to specify the use of [encoding.ProtoCodec] for (de)serialisation.
WithProtoJSON is an option to specify the use of [encoding.ProtoJSONCodec] for (de)serialisation.

# Interfaces

After is a handle on a Sleep operation which allows you to do other work concurrently with the sleep.
AwakeableFuture is a 'promise' to a future value or error, that can be resolved or rejected by other services.
Client represents all the different ways you can invoke a particular service-method.
Context is an extension of [RunContext] which is passed to Restate service handlers and enables interaction with Restate.
No description provided by the author
ObjectContext is an extension of [ObjectSharedContext] which is passed to exclusive-mode Virtual Object handlers.
ObjectSharedContext is an extension of [Context] which is passed to shared-mode Virtual Object handlers, giving read-only access to a snapshot of state.
ResponseFuture is a handle on a potentially not-yet completed outbound call.
RunContext is passed to [Run] closures and provides the limited set of Restate operations that are safe to use there.
Selector is an iterator over a list of blocking Restate operations that are running in the background.
SendClient allows making one-way invocations.
ServiceDefinition is the set of methods implemented by both services and virtual objects.
WorkflowContext is an extension of [WorkflowSharedContext] and [ObjectContext] which is passed to Workflow 'run' handlers, giving mutable access to state.
WorkflowSharedContext is an extension of [ObjectSharedContext] which is passed to shared-mode Workflow handlers, giving read-only access to a snapshot of state.

# Type aliases

re-export for use in generated code.
Code is a numeric status code for an error, typically a HTTP status code.
ObjectHandlerFn is the signature for a Virtual Object exclusive handler function.
ObjectSharedHandlerFn is the signature for a Virtual Object shared-mode handler function.
No description provided by the author
No description provided by the author
ServiceHandlerFn is the signature for a Service handler function.
Void is a placeholder to signify 'no value' where a type is otherwise needed.
ObjectHandlerFn is the signature for a Workflow 'Run' handler function.
WorkflowSharedHandlerFn is the signature for a Workflow shared handler function.