sdk

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 7 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 BinaryHeaderKey = "x-diverge-context-bin"

BinaryHeaderKey is the HTTP header key used to propagate the binary context.

View Source
const DefaultHeaderKey = "x-diverge-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 DecodePropagationContext added in v0.7.0

func DecodePropagationContext(encoded string) (*divergev1alpha1.PropagationContext, error)

DecodePropagationContext decodes a base64 string and unmarshals it into a PropagationContext.

func EncodePropagationContext added in v0.7.0

func EncodePropagationContext(ctx *divergev1alpha1.PropagationContext) (string, error)

EncodePropagationContext marshals a PropagationContext to protobuf and encodes it as base64.

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