Categorygithub.com/inngest/inngestgo
modulepackage
0.7.3
Repository: https://github.com/inngest/inngestgo.git
Documentation: pkg.go.dev

# README



A durable event-driven workflow engine SDK for Golang.
Read the documentation and get started in minutes.

GoDoc discord twitter


Inngest Go SDK

Inngest's Go SDK allows you to create event-driven, durable workflows in your existing API — without new infrastructure.

It's useful if you want to build reliable software without worrying about queues, events, subscribers, workers, or other complex primitives such as concurrency, parallelism, event batching, or distributed debounce. These are all built in.

Features

  • Type safe functions, durable workflows, and steps using generics
  • Event stream sampling built in
  • Declarative flow control (concurrency, prioritization, batching, debounce, rate limiting)
  • Zero-infrastructure. Inngest handles orchestration and calls your functions.

Examples

The following is the bare minimum setup for a fully distributed durable workflow server:

package main

import (
	"context"
	"fmt"
	"net/http"
	"time"

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

func main() {
	h := inngestgo.NewHandler("core", inngestgo.HandlerOpts{})
	f := inngestgo.CreateFunction(
		inngestgo.FunctionOpts{
			ID:   "account-created",
			Name: "Account creation flow",
		},
		// Run on every api/account.created event.
		inngestgo.EventTrigger("api/account.created", nil),
		AccountCreated,
	)
	h.Register(f)
	http.ListenAndServe(":8080", h)
}

// AccountCreated is a durable function which runs any time the "api/account.created"
// event is received by Inngest.
//
// It is invoked by Inngest, with each step being backed by Inngest's orchestrator.
// Function state is automatically managed, and persists across server restarts,
// cloud migrations, and language changes.
func AccountCreated(ctx context.Context, input inngestgo.Input[AccountCreatedEvent]) (any, error) {
	// Sleep for a second, minute, hour, week across server restarts.
	step.Sleep(ctx, "initial-delay", time.Second)

	// Run a step which emails the user.  This automatically retries on error.
	// This returns the fully typed result of the lambda.
	result, err := step.Run(ctx, "on-user-created", func(ctx context.Context) (bool, error) {
		// Run any code inside a step.
		result, err := emails.Send(emails.Opts{})
		return result, err
	})
	if err != nil {
		// This step retried 5 times by default and permanently failed.
		return nil, err
	}
	// `result` is  fully typed from the lambda
	_ = result

	// Sample from the event stream for new events.  The function will stop
	// running and automatially resume when a matching event is found, or if
	// the timeout is reached.
	fn, err := step.WaitForEvent[FunctionCreatedEvent](
		ctx,
		"wait-for-activity",
		step.WaitForEventOpts{
			Name:    "Wait for a function to be created",
			Event:   "api/function.created",
			Timeout: time.Hour * 72,
			// Match events where the user_id is the same in the async sampled event.
			If: inngestgo.StrPtr("event.data.user_id == async.data.user_id"),
		},
	)
	if err == step.ErrEventNotReceived {
		// A function wasn't created within 3 days.  Send a follow-up email.
		step.Run(ctx, "follow-up-email", func(ctx context.Context) (any, error) {
			// ...
			return true, nil
		})
		return nil, nil
	}

	// The event returned from `step.WaitForEvent` is fully typed.
	fmt.Println(fn.Data.FunctionID)

	return nil, nil
}

// AccountCreatedEvent represents the fully defined event received when an account is created.
//
// This is shorthand for defining a new Inngest-conforming struct:
//
//	type AccountCreatedEvent struct {
//		Name      string                  `json:"name"`
//		Data      AccountCreatedEventData `json:"data"`
//		User      any                     `json:"user"`
//		Timestamp int64                   `json:"ts,omitempty"`
//		Version   string                  `json:"v,omitempty"`
//	}
type AccountCreatedEvent inngestgo.GenericEvent[AccountCreatedEventData, any]
type AccountCreatedEventData struct {
	AccountID string
}

type FunctionCreatedEvent inngestgo.GenericEvent[FunctionCreatedEventData, any]
type FunctionCreatedEventData struct {
	FunctionID string
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

CreateFunction creates a new function which can be registered within a handler.
No description provided by the author
DevServerURL returns the URL for the Inngest dev server.
No description provided by the author
No description provided by the author
IsDev returns whether to use the dev server, by checking the presence of the INNGEST_DEV environment variable.
NewClient returns a concrete client initialized with the given ingest key, which can immediately send events to the ingest API.
NewHandler returns a new Handler for serving Inngest functions.
NowMillis returns a timestamp with millisecond precision used for the Event.Timestamp field.
Register adds the given functions to the default handler for serving.
Send uses the DefaultClient to send the given event.
SendMany uses the DefaultClient to send the given event batch.
Serve serves all registered functions within the default handler.
No description provided by the author
No description provided by the author
Sign signs a request body with the given key at the given timestamp.
No description provided by the author
Timestamp converts a go time.Time into a timestamp with millisecond precision used for the Event.Timestamp field.
ValidateSignature ensures that the signature for the given body is signed with the given key within a given time period to prevent invalid requests or replay attacks.

# Constants

Email is the field name used to reference the user's email.
ExternalID is the field name used to reference the user's ID within your systems.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

DefaultClient represents the default, mutable, global client used within the `Send` function provided by this package.
DefaultHandler provides a default handler for registering and serving functions globally.
DefaultMaxBodySize is the default maximum size read within a single incoming invoke request (100MB).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Re-export internal errors for users.
No description provided by the author

# Structs

No description provided by the author
Debounce represents debounce configuration used when creating a new function within FunctionOpts.
No description provided by the author
No description provided by the author
GenericEvent represents a single event generated from your system to be sent to Inngest.
No description provided by the author
Input is the input data passed to your function.
No description provided by the author
No description provided by the author
No description provided by the author
Throttle represents concurrency over time.
Timeouts represents timeouts for the function.

# Interfaces

Client represents a client used to send events to Inngest.
Handler represents a handler which serves the Inngest API via HTTP.
ServableFunction defines a function which can be called by a handler's Serve method.

# Type aliases

SDKFunction represents a user-defined function to be called based off of events or on a schedule.
No description provided by the author