sdk

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

Diverge SDK

Provides context propagation for Diverge's async routing (Temporal and Kafka). When a service in a preview environment calls Temporal or publishes to Kafka, the routing header (x-diverge-env) must propagate so downstream workers/consumers in the preview environment pick up the work instead of production workers.

Usage

Temporal Worker Setup
import "github.com/divergedev/diverge/pkg/sdk/temporal"

w := worker.New(c, temporal.TaskQueue("my-queue"), worker.Options{
    ContextPropagators: []workflow.ContextPropagator{
        temporal.NewContextPropagator(),
    },
})
Kafka Producer
import "github.com/divergedev/diverge/pkg/sdk/kafka"

topic, _ := kafka.Topic("my-topic", os.Getenv("DIVERGE_ENV"))
headers := kafka.Headers() // returns map[string]string with x-diverge-env

Documentation

Index

Constants

View Source
const DefaultHeaderKey = "x-preview-env"

DefaultHeaderKey is used to extract the preview environment name from the HTTP header.

Variables

View Source
var EnvContextKey = envContextKey{}

EnvContextKey is the key used to store the environment name in a context.

Functions

func EnvironmentFromContext

func EnvironmentFromContext(ctx context.Context) string

EnvironmentFromContext extracts the environment name from the context.

func GetHeaderKey added in v0.5.0

func GetHeaderKey() string

GetHeaderKey returns the header key from DIVERGE_HEADER_KEY or DefaultHeaderKey.

func WithEnvironment

func WithEnvironment(ctx context.Context, envName string) context.Context

WithEnvironment returns a context with the environment name set.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL