Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
kotlin-hello-world-lambda-cdk.zip

typescript-hello-world.zip
typescript-hello-world-kubernetes.zip
typescript-hello-world-bun.zip
typescript-hello-world-cloudflare-worker.zip
typescript-hello-world-deno.zip
Expand All @@ -73,6 +74,7 @@ jobs:
typescript-nextjs-fullstack.zip

go-hello-world.zip
go-hello-world-kubernetes.zip
go-hello-world-lambda-cdk.zip
go-tour-of-orchestration.zip
go-tour-of-workflows.zip
Expand Down Expand Up @@ -162,4 +164,4 @@ jobs:
secrets: inherit
with:
source-directory: go/templates/go
destination-repo: go-template
destination-repo: go-template
2 changes: 2 additions & 0 deletions .tools/prepare_release_zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ create_release_zip typescript/end-to-end-applications/chat-bot typescript-chat-b
create_release_zip typescript/end-to-end-applications/ai-image-workflows typescript-ai-image-workflows
create_release_zip typescript/patterns-use-cases typescript-patterns-use-cases
create_release_zip typescript/templates/node typescript-hello-world
create_release_zip typescript/templates/node-kubernetes typescript-hello-world-kubernetes
create_release_zip typescript/templates/lambda typescript-hello-world-lambda
create_release_zip typescript/templates/bun typescript-hello-world-bun
create_release_zip typescript/templates/cloudflare-worker typescript-hello-world-cloudflare-worker
Expand All @@ -69,6 +70,7 @@ create_release_zip go/integrations/go-lambda-cdk go-hello-world-lambda-cdk
create_release_zip go/integrations/knative-go go-knative-go
create_release_zip go/patterns-use-cases go-patterns-use-cases
create_release_zip go/templates/go go-hello-world
create_release_zip go/templates/go-kubernetes go-hello-world-kubernetes
create_release_zip go/tutorials/tour-of-orchestration-go go-tour-of-orchestration
create_release_zip go/tutorials/tour-of-workflows-go go-tour-of-workflows

Expand Down
1 change: 1 addition & 0 deletions .tools/run_go_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function go_build_check() {

go_build_check $PROJECT_ROOT/go/basics
go_build_check $PROJECT_ROOT/go/templates/go
go_build_check $PROJECT_ROOT/go/templates/go-kubernetes
go_build_check $PROJECT_ROOT/go/integrations/knative-go
go_build_check $PROJECT_ROOT/go/integrations/go-lambda-cdk/lambda
go_build_check $PROJECT_ROOT/go/tutorials/tour-of-orchestration-go
Expand Down
1 change: 1 addition & 0 deletions .tools/run_node_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function npm_install_check() {
npm_install_check $PROJECT_ROOT/typescript/basics

npm_install_check $PROJECT_ROOT/typescript/templates/node
npm_install_check $PROJECT_ROOT/typescript/templates/node-kubernetes
npm_install_check $PROJECT_ROOT/typescript/templates/lambda
npm_install_check $PROJECT_ROOT/typescript/templates/cloudflare-worker
npm_install_check $PROJECT_ROOT/typescript/templates/vercel
Expand Down
1 change: 1 addition & 0 deletions .tools/update_go_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function bump_go_sdk() {

bump_go_sdk $PROJECT_ROOT/go/basics
bump_go_sdk $PROJECT_ROOT/go/templates/go
bump_go_sdk $PROJECT_ROOT/go/templates/go-kubernetes
bump_go_sdk $PROJECT_ROOT/go/integrations/knative-go
bump_go_sdk $PROJECT_ROOT/go/integrations/go-lambda-cdk/lambda
bump_go_sdk $PROJECT_ROOT/go/tutorials/tour-of-orchestration-go
Expand Down
1 change: 1 addition & 0 deletions .tools/update_node_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function bump_restate_sdk_deps() {
# Update all projects with package.json
bump_restate_sdk_deps $PROJECT_ROOT/typescript/basics
bump_restate_sdk_deps $PROJECT_ROOT/typescript/templates/node
bump_restate_sdk_deps $PROJECT_ROOT/typescript/templates/node-kubernetes
bump_restate_sdk_deps $PROJECT_ROOT/typescript/templates/lambda
bump_restate_sdk_deps $PROJECT_ROOT/typescript/templates/typescript-testing
bump_restate_sdk_deps $PROJECT_ROOT/typescript/templates/bun
Expand Down
1 change: 1 addition & 0 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Examples integrating Restate with other tools and frameworks:
Starter templates for new projects:

- **[Go Template](templates/go)** [<img src="https://raw.githubusercontent.com/restatedev/img/refs/heads/main/play-button.svg" width="16" height="16">](templates/go/greeter.go)
- **[Go Kubernetes Template](templates/go-kubernetes)**: Deploy to Kubernetes with an in-process tunnel and Kubernetes YAML files.

## Tutorials

Expand Down
22 changes: 22 additions & 0 deletions go/templates/go-kubernetes/.agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "restatedev-plugin",
"interface": {
"displayName": "Restate"
},
"plugins": [
{
"name": "restatedev",
"source": {
"source": "git-subdir",
"url": "https://github.com/restatedev/skills.git",
"path": "./plugins/restatedev",
"ref": "main"
},
"policy": {
"installation": "AVAILABLE",
"authentication": "ON_INSTALL"
},
"category": "Coding"
}
]
}
13 changes: 13 additions & 0 deletions go/templates/go-kubernetes/.claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extraKnownMarketplaces": {
"restatedev-plugin": {
"source": {
"source": "github",
"repo": "restatedev/skills"
}
}
},
"enabledPlugins": {
"restatedev@restatedev-plugin": true
}
}
6 changes: 6 additions & 0 deletions go/templates/go-kubernetes/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.idea
.agents
.claude
*.zip
go-kubernetes
5 changes: 5 additions & 0 deletions go/templates/go-kubernetes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go-kubernetes

# Restate
.restate
restate-data
12 changes: 12 additions & 0 deletions go/templates/go-kubernetes/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.25 AS builder

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 go build -trimpath -o /service .

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=builder /service /service
ENTRYPOINT ["/service"]
16 changes: 16 additions & 0 deletions go/templates/go-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Hello world - Go Kubernetes template

Sample Restate service using the Go SDK, with an in-process tunnel, a Dockerfile, and Kubernetes YAML files.

See the [Kubernetes service deployment guide](https://docs.restate.dev/services/deploy/kubernetes) for more information on using this template to deploy to Kubernetes.

Build the container image with `docker build -t <registry>/my-restate-service:0.0.1 .`.
The Restate operator injects the tunnel configuration when using `tunnelMode: in-process`. The authentication token file is mounted on the deployment.

Invoke `Greeter/Greet` with a JSON object body: `{"name":"World"}`.

## Using AI coding tools

If you use Claude Code or Codex, then the Restate plugin will automatically be installed. For Cursor, consult the [skills repo README](https://github.com/restatedev/skills).

Plugin repo: https://github.com/restatedev/skills/tree/main
26 changes: 26 additions & 0 deletions go/templates/go-kubernetes/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/restatedev/examples/go/templates/go-kubernetes

go 1.25.0

require (
github.com/restatedev/sdk-go v1.0.3
github.com/restatedev/sdk-go/x/tunnel v0.1.1
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/invopop/jsonschema v0.14.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/pb33f/ordered-map/v2 v2.3.1 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect
go.opentelemetry.io/otel v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.yaml.in/yaml/v4 v4.0.0-rc.2 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/text v0.33.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
52 changes: 52 additions & 0 deletions go/templates/go-kubernetes/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang-jwt/jwt/v5 v5.2.3 h1:kkGXqQOBSDDWRhWNXTFpqGSCMyh/PLnqUvMGJPDJDs0=
github.com/golang-jwt/jwt/v5 v5.2.3/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/invopop/jsonschema v0.14.0 h1:MHQqLhvpNUZfw+hM3AZDYK7jxO8FZoQeQM77g8iyZjg=
github.com/invopop/jsonschema v0.14.0/go.mod h1:ygm6C2EaVNMBDPpaPlnOA2pFAxBnxGjFlMZABxm9n2I=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY=
github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/restatedev/sdk-go v1.0.3 h1:pDXoFot3eQk5T//2MpTTfwXsMtDgHeoh0grweW8kZxE=
github.com/restatedev/sdk-go v1.0.3/go.mod h1:wBPSXBOgBvwTQhLqujDSeW1BA480JXh6ZcIervk7tnA=
github.com/restatedev/sdk-go/x/tunnel v0.1.1 h1:fIuo9BdzKTJ5qFdDHlAEEctu5bLbFN7WJmxCs7omrk8=
github.com/restatedev/sdk-go/x/tunnel v0.1.1/go.mod h1:/KEBmcooRbYmnii0DiIIxC0vsuBuf0N4xBVAr3K+F3Q=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s=
go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
45 changes: 45 additions & 0 deletions go/templates/go-kubernetes/greeter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"time"

restate "github.com/restatedev/sdk-go"
)

// Greeter is a struct which represents a Restate service; reflection will turn exported methods into service handlers
type Greeter struct{}

type Greeting struct {
Name string `json:"name"`
}

func (Greeter) Greet(ctx restate.Context, greeting Greeting) (string, error) {
name := greeting.Name
// Durably execute a set of steps; resilient against failures
greetingId := restate.UUID(ctx).String()

if _, err := restate.Run(ctx,
func(ctx restate.RunContext) (restate.Void, error) {
return SendNotification(greetingId, name)
},
restate.WithName("Notification"),
); err != nil {
return "", err
}

if err := restate.Sleep(ctx, 1*time.Second); err != nil {
return "", err
}

if _, err := restate.Run(ctx,
func(ctx restate.RunContext) (restate.Void, error) {
return SendReminder(greetingId, name)
},
restate.WithName("Reminder"),
); err != nil {
return "", err
}

// Respond to caller
return "You said hi to " + name + "!", nil
}
12 changes: 12 additions & 0 deletions go/templates/go-kubernetes/k8s/cloud-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: restate.dev/v1beta1
kind: RestateCloudEnvironment
metadata:
name: my-cloud-env
spec:
environmentId: env_...
signingPublicKey: publickeyv1_...
region: eu
authentication:
secret:
name: my-cloud-environment-secret
key: token
32 changes: 32 additions & 0 deletions go/templates/go-kubernetes/k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: restate.dev/v1beta1
kind: RestateDeployment
metadata:
name: service
spec:
replicas: 1
restate:
register:
cloud: my-cloud-env
tunnelMode: in-process
selector:
matchLabels:
app: service
template:
metadata:
labels:
app: service
spec:
containers:
- name: service
image: <registry>/my-restate-service:0.0.1
env:
- name: RESTATE_INPROC_AUTH_TOKEN_FILE
value: /var/run/secrets/restate.cloud/token
volumeMounts:
- name: restate-cloud-tunnel-auth
mountPath: /var/run/secrets/restate.cloud
readOnly: true
volumes:
- name: restate-cloud-tunnel-auth
secret:
secretName: restate-cloud-tunnel-auth
27 changes: 27 additions & 0 deletions go/templates/go-kubernetes/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"

restate "github.com/restatedev/sdk-go"
"github.com/restatedev/sdk-go/server"
"github.com/restatedev/sdk-go/x/tunnel"
)

func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

srv := server.NewRestate().
Bind(restate.Reflect(Greeter{}))

// The Restate operator injects the RESTATE_INPROC_* tunnel configuration.
if err := tunnel.NewTunnel(srv).Start(ctx); err != nil {
slog.Error("application exited unexpectedly", "err", err.Error())
os.Exit(1)
}
}
25 changes: 25 additions & 0 deletions go/templates/go-kubernetes/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"
restate "github.com/restatedev/sdk-go"
"math/rand"
)

func SendNotification(greetingId string, name string) (restate.Void, error) {
if rand.Float32() < 0.7 && name == "Alice" { // 70% chance of failure
fmt.Printf("[👻 SIMULATED] Failed to send notification: %s - %s\n", greetingId, name)
return restate.Void{}, fmt.Errorf("[👻 SIMULATED] Failed to send notification: %s - %s", greetingId, name)
}
fmt.Printf("Notification sent: %s - %s\n", greetingId, name)
return restate.Void{}, nil
}

func SendReminder(greetingId string, name string) (restate.Void, error) {
if rand.Float32() < 0.7 && name == "Alice" { // 70% chance of failure
fmt.Printf("[👻 SIMULATED] Failed to send reminder: %s\n", greetingId)
return restate.Void{}, fmt.Errorf(" [👻 SIMULATED] Failed to send reminder: %s", greetingId)
}
fmt.Printf("Reminder sent: %s\n", greetingId)
return restate.Void{}, nil
}
Loading
Loading