Go SDK migration guide: v0.7 to v0.8

This guide will help you migrate your Inngest Go SDK from v0.7 to v0.8 by providing a summary of the breaking changes.

High-level

A minimal Inngest app looks like this:

import (
	"context"
	"net/http"

	"github.com/inngest/inngestgo"
)

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

	_, err = inngestgo.CreateFunction(
		client,
		inngestgo.FunctionOpts{ID: "my-fn"},
		inngestgo.EventTrigger("my-event", nil),
		func(
			ctx context.Context,
			input inngestgo.Input[inngestgo.GenericEvent[any, any]],
		) (any, error) {
			return "Hello, world!", nil
		},
	)
	if err != nil {
		panic(err)
	}

	_ = http.ListenAndServe(":8080", client.Serve())
}

Client

The DefaultClient was removed. You should now use the NewClient function to create a new client:

client, err := inngest.NewClient(inngest.ClientOpts{AppID: "my-app"})

AppID is now a required field. NewClient will return an error if it is not provided.

The removal of DefaultClient also means that inngestgo.Send and inngestgo.SendMany are no longer available. You should now use the Client.Send and Client.SendMany methods.

Handler

The Handler was removed, along with DefaultHandler and the NewHandler function. The handler is predominately replaced by the Client, with HandlerOpts being replaced by ClientOpts.

CreateFunction

CreateFunction now accepts a Client argument and returns an error. Calling CreateFunction automatically registers the function, obviating the Handler.Register method.

_, err := inngestgo.CreateFunction(
	client,
	inngestgo.FunctionOpts{ID: "my-fn"},
	inngestgo.EventTrigger("my-event", nil),
	func(
		ctx context.Context,
		input inngestgo.Input[inngestgo.GenericEvent[any, any]],
	) (any, error) {
		return "Hello, world!", nil
	},
)

ID is now a required field. CreateFunction will return an error if it is not provided.

If you were previously only setting the Name field, you can use inngestgo.Slugify to generate the same ID we used internally.

If inngestgo.CreateFunction is called in a different package than inngestgo.NewClient, then you must use a side-effect import to include the function:

import (
	"github.com/inngest/inngestgo"

	// Side-effect import to include functions declared in a different package.
	_ "github.com/myorg/myapp/fns"
)

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

	// ...
}