Go SDK

Install the Go SDK, create a client, and find the package reference.

The Go SDK defines durable functions, sends events, and serves your functions from any net/http server. It also runs Connect workers, supports checkpointing, and turns net/http handlers into Durable Endpoints. Some features are TypeScript-only for now; see feature support.

The full API reference for every package is on pkg.go.dev.

Install

go get github.com/inngest/inngestgo@latest

Create a client and serve functions

Create one client for your app, define functions with it, and serve them over HTTP:

main.go
package main

import (
	"context"
	"log"
	"net/http"

	"github.com/inngest/inngestgo"
	"github.com/inngest/inngestgo/step"
)

func main() {
	client, err := inngestgo.NewClient(inngestgo.ClientOpts{AppID: "my-app"})
	if err != nil {
		log.Fatal(err)
	}

	_, err = inngestgo.CreateFunction(
		client,
		inngestgo.FunctionOpts{ID: "process-task"},
		inngestgo.EventTrigger("app/task.created", nil),
		func(ctx context.Context, input inngestgo.Input[map[string]any]) (any, error) {
			return step.Run(ctx, "handle-task", func(ctx context.Context) (map[string]any, error) {
				return map[string]any{"processed": true}, nil
			})
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	http.Handle("/api/inngest", client.Serve())
	log.Fatal(http.ListenAndServe(":8080", nil))
}

The Go quick start walks through a full example with the Dev Server. See Durable Workflows in Go for triggers, steps, errors, and function options.

Durable Endpoints

Durable Endpoints (beta) run a net/http handler as an Inngest function, so the handler can use step.Run and the other step tools. Create one stephttp provider when the process starts:

steps.go
import "github.com/inngest/inngestgo/stephttp"

// Create one provider when the process starts, and use it for every handler.
var steps = stephttp.Setup(stephttp.SetupOpts{})

Then wrap each handler that should be a function:

orders.go
import (
	"context"
	"encoding/json"
	"net/http"

	"github.com/inngest/inngestgo/step"
	"github.com/inngest/inngestgo/stephttp"
)

// steps is the provider from stephttp.Setup, created once at startup.
func RegisterRoutes(mux *http.ServeMux, steps stephttp.Provider) {
	mux.HandleFunc("POST /api/orders", steps.HandleFunc(stephttp.FnOpts{}, handleOrder))
}

func handleOrder(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	var body struct {
		OrderID string `json:"orderId"`
	}
	_ = json.NewDecoder(r.Body).Decode(&body)

	if body.OrderID == "" {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusBadRequest)
		_ = json.NewEncoder(w).Encode(map[string]string{"error": "orderId is required"})
		return
	}

	order, err := step.Run(ctx, "load-order", func(ctx context.Context) (Order, error) {
		return loadOrder(ctx, body.OrderID)
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	reservation, err := step.Run(ctx, "reserve-inventory", func(ctx context.Context) (Reservation, error) {
		return reserveInventory(ctx, order)
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	_ = json.NewEncoder(w).Encode(map[string]any{
		"orderId":     body.OrderID,
		"reservation": reservation,
	})
}

Durable Endpoints need inngestgo v0.16.5 or later. See Durable Endpoints in Go to wait for runs at shutdown, add middleware to a router, wrap handlers you can't register yourself, and configure functions.

Packages

PackageUse it for
inngestgoThe client, functions, triggers, events, Serve(), and Connect()
inngestgo/stepStep tools such as step.Run, step.Sleep, step.WaitForEvent, and step.Invoke
inngestgo/errorsRetry control, such as non-retriable errors
inngestgo/pkg/checkpointCheckpointing configuration
inngestgo/stephttpDurable Endpoints (beta)
inngestgo/realtimeRealtime publish and subscribe

Guides

Migrations

Source code

The Go SDK is open source on GitHub: inngest/inngestgo.