Documentation
¶
Index ¶
- Constants
- Variables
- func DecodePropagationContext(encoded string) (*divergev1alpha1.PropagationContext, error)
- func EncodePropagationContext(ctx *divergev1alpha1.PropagationContext) (string, error)
- func EnvironmentFromContext(ctx context.Context) string
- func GetHeaderKey() string
- func ResolveRedisKey(ctx context.Context, key string) string
- func ResolveRedisPrefix(ctx context.Context) string
- func ResolveStorageKey(ctx context.Context, key string) string
- func ResolveStoragePrefix(ctx context.Context) string
- func WithEnvironment(ctx context.Context, envName string) context.Context
Constants ¶
const BinaryHeaderKey = "x-diverge-context-bin"
BinaryHeaderKey is the HTTP header key used to propagate the binary context.
const DefaultHeaderKey = "x-diverge-env"
DefaultHeaderKey is used to extract the preview environment name from the HTTP header.
Variables ¶
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 ¶
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 ResolveRedisKey ¶ added in v0.17.0
ResolveRedisKey prefixes a Redis/Valkey key with the active preview prefix. It is idempotent: if key already starts with the resolved prefix, it is returned unchanged.
func ResolveRedisPrefix ¶ added in v0.17.0
ResolveRedisPrefix returns the active Redis/Valkey key prefix for the current preview environment. Priority:
- DIVERGE_REDIS_PREFIX or REDIS_KEY_PREFIX environment variable (ensuring a trailing ":").
- Active environment from context (or DIVERGE_ENV fallback), formatted as "preview:<env>:".
- Empty string "" when running in baseline/production without an active preview environment.
func ResolveStorageKey ¶ added in v0.19.0
ResolveStorageKey prefixes an S3/GCS/MinIO object key with the active preview prefix. It is idempotent: if key already starts with the resolved prefix, it is returned without duplicate prefixing.
func ResolveStoragePrefix ¶ added in v0.19.0
ResolveStoragePrefix returns the active S3/GCS/MinIO object key prefix for the current preview environment. Priority:
- DIVERGE_STORAGE_PREFIX, S3_KEY_PREFIX, AWS_S3_PREFIX, or GCS_KEY_PREFIX environment variable (trimmed of leading "/" and normalized with a trailing "/").
- Active environment from context (or DIVERGE_ENV fallback), formatted as "previews/<ns>/<env>/" when DIVERGE_NAMESPACE or POD_NAMESPACE is set, or "previews/<env>/" otherwise.
- Empty string "" when running in baseline/production without an active preview environment.
Types ¶
This section is empty.