context

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Package context provides a context for accessing services

Package metadata is a way of defining message headers

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultContext is a context which can be used to access micro services
	DefaultContext = WithNamespace("micro")

	NamespaceKey = "Micro-Namespace"
)

Functions

func Delete

func Delete(ctx context.Context, k string) context.Context

Delete key from metadata

func Get

func Get(ctx context.Context, key string) (string, bool)

Get returns a single value from metadata in the context

func GetMetadata

func GetMetadata(ctx context.Context, k string) (string, bool)

GetMetadata returns metadata from the context

func MergeContext

func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context.Context

MergeContext merges metadata to existing metadata, overwriting if specified

func NewContext

func NewContext(ctx context.Context, md Metadata) context.Context

NewContext creates a new context with the given metadata

func Set

func Set(ctx context.Context, k, v string) context.Context

Set add key with val to metadata

func SetMetadata

func SetMetadata(ctx context.Context, k, v string) context.Context

SetMetadata sets the metadata within the context

func SetNamespace

func SetNamespace(ctx context.Context, ns string) context.Context

SetNamespace sets the namespace for a context

func WithNamespace

func WithNamespace(ns string) context.Context

WithNamespace creates a new context with the given namespace

Types

type Metadata

type Metadata map[string]string

Metadata is our way of representing request headers internally. They're used at the RPC level and translate back and forth from Transport headers.

func Copy

func Copy(md Metadata) Metadata

Copy makes a copy of the metadata

func FromContext

func FromContext(ctx context.Context) (Metadata, bool)

FromContext returns metadata from the given context

func (Metadata) Delete

func (md Metadata) Delete(key string)

func (Metadata) Get

func (md Metadata) Get(key string) (string, bool)

func (Metadata) Set

func (md Metadata) Set(key, val string)

Directories

Path Synopsis
metadata module

Jump to

Keyboard shortcuts

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