metadata

package
v0.0.0-...-037b315 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UIDKey      = "x-md-global-uid"
	CmdKey      = "x-md-cmd"
	GateAddrKey = "x-md-global-gate" //存储gatesrv地址
)

定义一些游戏里面需要使用到的key

Variables

This section is empty.

Functions

func AddUIDFromMDCtx

func AddUIDFromMDCtx(ctx context.Context) context.Context

AddUIDFromMDCtx 如果uidKey结构的ctx中没有uid,就从metadata中提取uid,存储到uidKey中

func AppendToClientContext

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

AppendToClientContext returns a new context with the provided kv merged with any existing metadata in the context.

func AppendUIDToClientContext

func AppendUIDToClientContext(ctx context.Context, uid string) context.Context

func CloneToClientContext

func CloneToClientContext(src context.Context) (dst context.Context)

func CloneToServerContext

func CloneToServerContext(src context.Context) (dst context.Context)

func FromCmdContext

func FromCmdContext(ctx context.Context) string

func FromGateContext

func FromGateContext(ctx context.Context) (string, bool)

func FromUIDContext

func FromUIDContext(ctx context.Context) (uid string, ok bool)

FromUIDContext 从uidKey结构里面获取uid

func GetUID

func GetUID(ctx context.Context) string

GetUID 从先从uidKey结构获取uid,如果uid不存在,再从metadata里面获取uid

func GetUIDFromClientContext

func GetUIDFromClientContext(ctx context.Context) string

func GetUIDFromMDCtx

func GetUIDFromMDCtx(ctx context.Context) string

GetUIDFromMDCtx 根据ctx获取metadata,再从metadata里面获取uid

func MergeToClientContext

func MergeToClientContext(ctx context.Context, cmd Metadata) context.Context

MergeToClientContext merge new metadata into ctx.

func NewClientContext

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

NewClientContext creates a new context with client md attached.

func NewClientUIDContext

func NewClientUIDContext(ctx context.Context, uid string) context.Context

func NewServerContext

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

NewServerContext creates a new context with client md attached.

func NewUIDContext

func NewUIDContext(ctx context.Context, uid string) context.Context

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 FromClientContext

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

FromClientContext returns the client metadata in ctx if it exists.

func FromServerContext

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

FromServerContext returns the server metadata in ctx if it exists.

func New

func New(mds ...map[string]string) Metadata

New creates an MD from a given key-values map.

func (Metadata) Clone

func (m Metadata) Clone() Metadata

Clone returns a deep copy of Metadata

func (Metadata) Get

func (m Metadata) Get(key string) string

Get returns the value associated with the passed key.

func (Metadata) Keys

func (m Metadata) Keys() []string

func (Metadata) Range

func (m Metadata) Range(f func(k, v string) bool)

Range iterate over element in metadata.

func (Metadata) Set

func (m Metadata) Set(key string, value string)

Set stores the key-value pair.

Jump to

Keyboard shortcuts

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