headers

package
v1.36.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CallerTypeOperator       = "operator"
	CallerTypeAPI            = "api"
	CallerTypeBackgroundHigh = "background_high"
	CallerTypeBackgroundLow  = "background_low"
	CallerTypePreemptable    = "preemptable"

	CallerNameSystem = "system"
)
View Source
const (
	ClientNameHeaderName              = "client-name"
	ClientVersionHeaderName           = "client-version"
	SupportedServerVersionsHeaderName = "supported-server-versions"
	SupportedFeaturesHeaderName       = "supported-features"
	SupportedFeaturesHeaderDelim      = ","

	CallerNameHeaderName = "caller-name"
	CallerTypeHeaderName = "caller-type"
	CallOriginHeaderName = "call-initiation"

	ExperimentHeaderName = "temporal-experiment"
)

Note the nexusoperations component references these headers and adds them to a list of disallowed headers for users to set. If any other headers are added for internal use, they should be added to the disallowed headers list.

View Source
const (
	ClientNameServer        = "temporal-server"
	ClientNameServerHTTP    = "temporal-server-http"
	ClientNameGoSDK         = "temporal-go"
	ClientNameJavaSDK       = "temporal-java"
	ClientNamePHPSDK        = "temporal-php"
	ClientNameTypeScriptSDK = "temporal-typescript"
	ClientNamePythonSDK     = "temporal-python"
	ClientNameCLI           = "temporal-cli"
	ClientNameUI            = "temporal-ui"
	ClientNameNexusGoSDK    = "Nexus-go-sdk"

	// ServerVersion value can be changed by the create-tag Github workflow.
	// If you change the var name or move it, be sure to update the workflow.
	ServerVersion = "1.32.0"

	// SupportedServerVersions is used by CLI and inter role communication.
	SupportedServerVersions = ">=1.0.0 <2.0.0"

	// FeatureFollowsNextRunID means that the client supports following next execution run id for
	// completed/failed/timedout completion events when getting the final result of a workflow.
	FeatureFollowsNextRunID = "follows-next-run-id"
)

Variables

View Source
var (
	SystemOperatorCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypeOperator,
	}
	SystemBackgroundHighCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypeBackgroundHigh,
	}
	SystemBackgroundLowCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypeBackgroundLow,
	}
	SystemPreemptableCallerInfo = CallerInfo{
		CallerName: CallerNameSystem,
		CallerType: CallerTypePreemptable,
	}
)
View Source
var (
	// AllFeatures contains all known features. This list is used as the value of the supported
	// features header for internal server requests. There is an assumption that if a feature is
	// defined, then the server itself supports it.
	AllFeatures = strings.Join([]string{
		FeatureFollowsNextRunID,
	}, SupportedFeaturesHeaderDelim)

	SupportedClients = map[string]string{
		ClientNameGoSDK:         "<2.0.0",
		ClientNameJavaSDK:       "<2.0.0",
		ClientNamePHPSDK:        "<2.0.0",
		ClientNameTypeScriptSDK: "<2.0.0",
		ClientNameCLI:           "<2.0.0",
		ClientNameServer:        "<2.0.0",
		ClientNameUI:            "<3.0.0",
		ClientNameNexusGoSDK:    "<2.0.0",
	}
)

Functions

func GetClientNameAndVersion

func GetClientNameAndVersion(ctx context.Context) (string, string)

GetClientNameAndVersion extracts SDK name and version from context headers

func GetValues

func GetValues(ctx context.Context, headerNames ...string) []string

GetValues returns header values for passed header names. It always returns slice of the same size as number of passed header names.

func IsExperimentRequested

func IsExperimentRequested(ctx context.Context, experiment string) bool

IsExperimentRequested checks if a specific experiment is present in the temporal-experiment header. Returns true if the experiment is explicitly listed or if "*" (wildcard) is present. Headers exceeding a length of 100 will be skipped.

func NewDefaultVersionChecker

func NewDefaultVersionChecker() *versionChecker

NewDefaultVersionChecker constructs a new VersionChecker using default versions from const.

func NewVersionChecker

func NewVersionChecker(supportedClients map[string]string, serverVersion string) *versionChecker

NewVersionChecker constructs a new VersionChecker

func Propagate

func Propagate(ctx context.Context) context.Context

Propagate propagates version headers from incoming context to outgoing context. It copies all headers to outgoing context only if they are exist in incoming context and doesn't exist in outgoing context already.

func SetCallerInfo

func SetCallerInfo(
	ctx context.Context,
	info CallerInfo,
) context.Context

SetCallerInfo sets callerName, callerType and CallOrigin in the context. Existing values will be overwritten if new value is not empty. TODO: consider only set the caller info to golang context instead of grpc metadata and propagate to grpc outgoing context upon making an rpc call

func SetCallerName

func SetCallerName(
	ctx context.Context,
	callerName string,
) context.Context

SetCallerName set caller name in the context. Existing caller name will be overwritten if exists and new caller name is not empty.

func SetCallerType

func SetCallerType(
	ctx context.Context,
	callerType string,
) context.Context

SetCallerType set caller type in the context. Existing caller type will be overwritten if exists and new caller type is not empty.

func SetOrigin

func SetOrigin(
	ctx context.Context,
	callOrigin string,
) context.Context

SetOrigin set call origin in the context. Existing call origin will be overwritten if exists and new call origin is not empty.

func SetVersions

func SetVersions(ctx context.Context) context.Context

SetVersions sets headers for internal communications.

func SetVersionsForTests

func SetVersionsForTests(ctx context.Context, clientVersion, clientName, supportedServerVersions, supportedFeatures string) context.Context

SetVersionsForTests sets headers as they would be received from the client. Must be used in tests only.

Types

type CallerInfo

type CallerInfo struct {
	// CallerName is the name of the caller.
	// It can either user namespace name or
	// the predefined CallerNameSystem.
	CallerName string

	// CallerType indicates if the call originates from
	// user API calls or from system background operations.
	CallerType string

	// CallOrigin is the first API method name in the call chain.
	// Currently, its value is valid only when CallerType is CallerTypeAPI or CallerTypeOperator.
	CallOrigin string
}

func GetCallerInfo

func GetCallerInfo(
	ctx context.Context,
) CallerInfo

GetCallerInfo retrieves caller information from the context if exists. Empty value is returned if any piece of caller information is not specified in the context.

func NewBackgroundHighCallerInfo

func NewBackgroundHighCallerInfo(
	callerName string,
) CallerInfo

NewBackgroundHighCallerInfo creates a new CallerInfo with BackgroundHigh callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypeBackgroundHigh, "")

func NewBackgroundLowCallerInfo

func NewBackgroundLowCallerInfo(
	callerName string,
) CallerInfo

NewBackgroundLowCallerInfo creates a new CallerInfo with BackgroundLow callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypeBackgroundLow, "")

func NewCallerInfo

func NewCallerInfo(
	callerName string,
	callerType string,
	callOrigin string,
) CallerInfo

NewCallerInfo creates a new CallerInfo

func NewPreemptableCallerInfo

func NewPreemptableCallerInfo(
	callerName string,
) CallerInfo

NewPreemptableCallerInfo creates a new CallerInfo with Preemptable callerType and empty callOrigin. This is equivalent to NewCallerInfo(callerName, CallerTypePreemptable, "")

type GRPCHeaderGetter

type GRPCHeaderGetter struct {
	// contains filtered or unexported fields
}

Wrapper for gRPC metadata that exposes a helper to extract a single metadata value.

func NewGRPCHeaderGetter

func NewGRPCHeaderGetter(ctx context.Context) GRPCHeaderGetter

func (GRPCHeaderGetter) Get

func (h GRPCHeaderGetter) Get(key string) string

Get a single value from the underlying gRPC metadata. Returns an empty string if the metadata key is unset.

type HeaderGetter

type HeaderGetter interface {
	Get(string) string
}

HeaderGetter is an interface for getting a single header value from a case insensitive key.

type VersionChecker

type VersionChecker interface {
	ClientSupported(ctx context.Context) error
	ClientSupportsFeature(ctx context.Context, feature string) bool
}

VersionChecker is used to check client/server compatibility and client's capabilities

Jump to

Keyboard shortcuts

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