metadata

package
v4.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 5 Imported by: 7

Documentation

Overview

Package metadata is a way of defining message headers

Index

Constants

This section is empty.

Variables

View Source
var (
	// HeaderTopic is the header name that contains topic name
	HeaderTopic = "Micro-Topic"
	// HeaderContentType specifies content type of message
	HeaderContentType = "Content-Type"
	// HeaderEndpoint specifies endpoint in service
	HeaderEndpoint = "Micro-Endpoint"
	// HeaderService specifies service
	HeaderService = "Micro-Service"
	// HeaderTimeout specifies timeout of operation
	HeaderTimeout = "Micro-Timeout"
	// HeaderAuthorization specifies Authorization header
	HeaderAuthorization = "Authorization"
	// HeaderXRequestID specifies request id
	HeaderXRequestID = "X-Request-Id"
)

Functions

func AppendContext added in v4.1.0

func AppendContext(ctx context.Context, kv ...string) context.Context

AppendContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.

func AppendIncomingContext

func AppendIncomingContext(ctx context.Context, kv ...string) context.Context

AppendIncomingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.

func AppendOutgoingContext

func AppendOutgoingContext(ctx context.Context, kv ...string) context.Context

AppendOutgoingContext returns a new context with the provided kv merged with any existing metadata in the context. Please refer to the documentation of Pairs for a description of kv.

func NewContext

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

NewContext creates a new context with Metadata attached. Metadata must not be modified after calling this function.

func NewIncomingContext

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

NewIncomingContext creates a new context with incoming Metadata attached. Metadata must not be modified after calling this function.

func NewOutgoingContext

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

NewOutgoingContext creates a new context with outgoing Metadata attached. If used in conjunction with AppendOutgoingContext, NewOutgoingContext will overwrite any previously-appended metadata. Metadata must not be modified after calling this function.

func ValueFromCurrentContext added in v4.1.0

func ValueFromCurrentContext(ctx context.Context, key string) []string

ValueFromCurrentContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.

func ValueFromIncomingContext added in v4.1.0

func ValueFromIncomingContext(ctx context.Context, key string) []string

ValueFromIncomingContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.

func ValueFromOutgoingContext added in v4.1.0

func ValueFromOutgoingContext(ctx context.Context, key string) []string

ValueFromOutgoingContext returns the metadata value corresponding to the metadata key from the incoming metadata if it exists. Keys are matched in a case insensitive manner.

Types

type Iterator

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

Iterator used to iterate over metadata with order

func (*Iterator) Next

func (iter *Iterator) Next(k *string, v *[]string) bool

Next advance iterator to next element

type Metadata

type Metadata map[string][]string

Metadata is a mapping from metadata keys to values. Users should use the following two convenience functions New and Pairs to generate Metadata.

func Copy

func Copy(src Metadata) Metadata

Copy returns a copy of Metadata.

func FromContext

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

FromContext returns the metadata in ctx if it exists.

func FromIncomingContext

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

FromIncomingContext returns the incoming metadata in ctx if it exists.

func FromOutgoingContext

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

FromOutgoingContext returns the outgoing metadata in ctx if it exists.

func Join added in v4.1.0

func Join(mds ...Metadata) Metadata

Join joins any number of Metadatas into a single Metadata.

The order of values for each key is determined by the order in which the Metadatas containing those values are presented to Join.

func MustContext added in v4.1.0

func MustContext(ctx context.Context) Metadata

MustContext returns the metadata in ctx.

func MustIncomingContext added in v4.1.0

func MustIncomingContext(ctx context.Context) Metadata

MustIncomingContext returns the incoming metadata in ctx.

func MustOutgoingContext added in v4.1.0

func MustOutgoingContext(ctx context.Context) Metadata

MustOutgoingContext returns the outgoing metadata in ctx.

func New

func New(l int) Metadata

New creates an zero Metadata.

func NewWithMetadata added in v4.1.0

func NewWithMetadata(m map[string]string) Metadata

NewWithMetadata creates an Metadata from a given key-value map.

func Pairs

func Pairs(kv ...string) Metadata

Pairs returns an Metadata formed by the mapping of key, value ... Pairs panics if len(kv) is odd.

func (Metadata) Add added in v4.1.0

func (md Metadata) Add(key string, vals ...string)

Set sets the value of a given key with a slice of values.

func (Metadata) Append added in v4.0.18

func (md Metadata) Append(key string, vals ...string)

Append adds the values to key k, not overwriting what was already stored at that key.

func (Metadata) AsHTTP1 added in v4.1.0

func (md Metadata) AsHTTP1() map[string][]string

AsHTTP1 returns a copy of Metadata with CanonicalMIMEHeaderKey.

func (Metadata) AsHTTP2 added in v4.1.0

func (md Metadata) AsHTTP2() map[string][]string

AsHTTP1 returns a copy of Metadata with strings.ToLower.

func (Metadata) Copy added in v4.1.0

func (md Metadata) Copy() Metadata

Copy returns a copy of Metadata.

func (Metadata) CopyTo added in v4.1.0

func (md Metadata) CopyTo(out Metadata)

CopyTo copies Metadata to out.

func (Metadata) Del

func (md Metadata) Del(k ...string)

Del removes the values for a given keys k.

func (Metadata) Get

func (md Metadata) Get(k string) ([]string, bool)

Get obtains the values for a given key.

func (Metadata) GetJoined added in v4.1.0

func (md Metadata) GetJoined(k string) (string, bool)

GetJoined obtains the values for a given key with joined values with "," symbol

func (Metadata) Iterator

func (md Metadata) Iterator() *Iterator

Iterator returns the itarator for metadata in sorted order

func (Metadata) Len added in v4.1.0

func (md Metadata) Len() int

Len returns the number of items in Metadata.

func (Metadata) MustGet added in v4.1.0

func (md Metadata) MustGet(k string) []string

Get obtains the values for a given key.

func (Metadata) MustGetJoined added in v4.1.0

func (md Metadata) MustGetJoined(k string) string

MustGetJoined obtains the values for a given key with joined values with "," symbol

func (Metadata) Set

func (md Metadata) Set(kvs ...string)

Set sets the value of a given key with a slice of values.

Jump to

Keyboard shortcuts

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