metadata

package
v0.0.0-...-c27d938 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

metautils

import "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"

Overview

Imported Packages

Index

Package files

doc.go nicemd.go single_key.go

type NiceMD

type NiceMD metadata.MD

NiceMD is a convenience wrapper definiting extra functions on the metadata.

func ExtractIncoming
func ExtractIncoming(ctx context.Context) NiceMD

ExtractIncoming extracts an inbound metadata from the server-side context.

This function always returns a NiceMD wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty NiceMD.

func ExtractOutgoing
func ExtractOutgoing(ctx context.Context) NiceMD

ExtractOutgoing extracts an outbound metadata from the client-side context.

This function always returns a NiceMD wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty NiceMD.

func (NiceMD) Add
func (m NiceMD) Add(key string, value string) NiceMD

Add retrieves a single value from the metadata.

It works analogously to http.Header.Add, as it appends to any existing values associated with key.

The function is binary-key safe.

func (NiceMD) Clone
func (m NiceMD) Clone(copiedKeys ...string) NiceMD

Clone performs a deep copy of the metadata.MD.

You can specify the lower-case copiedKeys to only copy certain whitelisted keys. If no keys are explicitly whitelisted all keys get copied.

func (NiceMD) Del
func (m NiceMD) Del(key string) NiceMD
func (NiceMD) Get
func (m NiceMD) Get(key string) string

Get retrieves a single value from the metadata.

It works analogously to http.Header.Get, returning the first value if there are many set. If the value is not set, an empty string is returned.

The function is binary-key safe.

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

Set sets the given value in a metadata.

It works analogously to http.Header.Set, overwriting all previous metadata values.

The function is binary-key safe.

func (NiceMD) ToIncoming
func (m NiceMD) ToIncoming(ctx context.Context) context.Context

ToIncoming sets the given NiceMD as a server-side context for dispatching.

This is mostly useful in ServerInterceptors..

func (NiceMD) ToOutgoing
func (m NiceMD) ToOutgoing(ctx context.Context) context.Context

ToOutgoing sets the given NiceMD as a client-side context for dispatching.


Generated by godoc2ghmd

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RpcErrorFromMD

func RpcErrorFromMD(md metadata.MD) (rpcErr *bkproto.TLRpcError)

RpcErrorFromMD Server To Client

func RpcErrorToMD

func RpcErrorToMD(md *bkproto.TLRpcError) (metadata.MD, error)

func RpcMetadataToOutgoing

func RpcMetadataToOutgoing(ctx context.Context, md *RpcMetadata) (context.Context, error)

Types

type MD

type MD = metadata.MD

type NiceMD

type NiceMD metadata.MD

NiceMD is a convenience wrapper definiting extra functions on the metadata.

func ExtractIncoming

func ExtractIncoming(ctx context.Context) NiceMD

ExtractIncoming extracts an inbound metadata from the server-side context.

This function always returns a NiceMD wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty NiceMD.

func ExtractOutgoing

func ExtractOutgoing(ctx context.Context) NiceMD

ExtractOutgoing extracts an outbound metadata from the client-side context.

This function always returns a NiceMD wrapper of the metadata.MD, in case the context doesn't have metadata it returns a new empty NiceMD.

func (NiceMD) Add

func (m NiceMD) Add(key string, value string) NiceMD

Add retrieves a single value from the metadata.

It works analogously to http.Header.Add, as it appends to any existing values associated with key.

The function is binary-key safe.

func (NiceMD) Clone

func (m NiceMD) Clone(copiedKeys ...string) NiceMD

Clone performs a *deep* copy of the metadata.MD.

You can specify the lower-case copiedKeys to only copy certain whitelisted keys. If no keys are explicitly whitelisted all keys get copied.

func (NiceMD) Del

func (m NiceMD) Del(key string) NiceMD

func (NiceMD) Get

func (m NiceMD) Get(key string) string

Get retrieves a single value from the metadata.

It works analogously to http.Header.Get, returning the first value if there are many set. If the value is not set, an empty string is returned.

The function is binary-key safe.

func (NiceMD) Set

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

Set sets the given value in a metadata.

It works analogously to http.Header.Set, overwriting all previous metadata values.

The function is binary-key safe.

func (NiceMD) ToIncoming

func (m NiceMD) ToIncoming(ctx context.Context) context.Context

ToIncoming sets the given NiceMD as a server-side context for dispatching.

This is mostly useful in ServerInterceptors..

func (NiceMD) ToOutgoing

func (m NiceMD) ToOutgoing(ctx context.Context) context.Context

ToOutgoing sets the given NiceMD as a client-side context for dispatching.

type RpcMetadata

type RpcMetadata struct {
	ServerId             string   `protobuf:"bytes,1,opt,name=server_id,json=serverId,proto3" json:"server_id,omitempty"`
	ClientAddr           string   `protobuf:"bytes,2,opt,name=client_addr,json=clientAddr,proto3" json:"client_addr,omitempty"`
	AuthId               int64    `protobuf:"varint,3,opt,name=auth_id,json=authId,proto3" json:"auth_id,omitempty"`
	SessionId            int64    `protobuf:"varint,4,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
	ReceiveTime          int64    `protobuf:"varint,5,opt,name=receive_time,json=receiveTime,proto3" json:"receive_time,omitempty"`
	UserId               int64    `protobuf:"varint,6,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	ClientMsgId          int64    `protobuf:"varint,7,opt,name=client_msg_id,json=clientMsgId,proto3" json:"client_msg_id,omitempty"`
	IsBot                bool     `protobuf:"varint,8,opt,name=is_bot,json=isBot,proto3" json:"is_bot,omitempty"`
	SchemaName           string   `protobuf:"bytes,9,opt,name=schema_name,json=schemaName,proto3" json:"schema_name,omitempty"`
	Layer                int32    `protobuf:"varint,10,opt,name=layer,proto3" json:"layer,omitempty"`
	Client               string   `protobuf:"bytes,11,opt,name=client,proto3" json:"client,omitempty"`
	IsAdmin              bool     `protobuf:"varint,12,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty"`
	Takeout              *Takeout `protobuf:"bytes,13,opt,name=takeout,proto3" json:"takeout,omitempty"`
	LangCode             string   `protobuf:"bytes,14,opt,name=lang_code,json=langCode,proto3" json:"lang_code,omitempty"`
	PermAuthKeyId        int64    `protobuf:"varint,15,opt,name=perm_auth_key_id,json=permAuthKeyId,proto3" json:"perm_auth_key_id,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func RpcMetadataFromIncoming

func RpcMetadataFromIncoming(ctx context.Context) *RpcMetadata

func RpcMetadataFromMD

func RpcMetadataFromMD(md metadata.MD) (*RpcMetadata, error)

func (*RpcMetadata) DebugString

func (m *RpcMetadata) DebugString() string

func (*RpcMetadata) Descriptor

func (*RpcMetadata) Descriptor() ([]byte, []int)

func (*RpcMetadata) GetAuthId

func (m *RpcMetadata) GetAuthId() int64

func (*RpcMetadata) GetClient

func (m *RpcMetadata) GetClient() string

func (*RpcMetadata) GetClientAddr

func (m *RpcMetadata) GetClientAddr() string

func (*RpcMetadata) GetClientMsgId

func (m *RpcMetadata) GetClientMsgId() int64

func (*RpcMetadata) GetIsAdmin

func (m *RpcMetadata) GetIsAdmin() bool

func (*RpcMetadata) GetIsBot

func (m *RpcMetadata) GetIsBot() bool

func (*RpcMetadata) GetLangCode

func (m *RpcMetadata) GetLangCode() string

func (*RpcMetadata) GetLayer

func (m *RpcMetadata) GetLayer() int32

func (*RpcMetadata) GetPermAuthKeyId

func (m *RpcMetadata) GetPermAuthKeyId() int64

func (*RpcMetadata) GetReceiveTime

func (m *RpcMetadata) GetReceiveTime() int64

func (*RpcMetadata) GetSchemaName

func (m *RpcMetadata) GetSchemaName() string

func (*RpcMetadata) GetServerId

func (m *RpcMetadata) GetServerId() string

func (*RpcMetadata) GetSessionId

func (m *RpcMetadata) GetSessionId() int64

func (*RpcMetadata) GetTakeout

func (m *RpcMetadata) GetTakeout() *Takeout

func (*RpcMetadata) GetTakeoutId

func (m *RpcMetadata) GetTakeoutId() int64

func (*RpcMetadata) GetUserId

func (m *RpcMetadata) GetUserId() int64

func (*RpcMetadata) HasTakeout

func (m *RpcMetadata) HasTakeout() bool

func (*RpcMetadata) ProtoMessage

func (*RpcMetadata) ProtoMessage()

func (*RpcMetadata) Reset

func (m *RpcMetadata) Reset()

func (*RpcMetadata) String

func (m *RpcMetadata) String() string

func (*RpcMetadata) XXX_DiscardUnknown

func (m *RpcMetadata) XXX_DiscardUnknown()

func (*RpcMetadata) XXX_Marshal

func (m *RpcMetadata) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RpcMetadata) XXX_Merge

func (m *RpcMetadata) XXX_Merge(src proto.Message)

func (*RpcMetadata) XXX_Size

func (m *RpcMetadata) XXX_Size() int

func (*RpcMetadata) XXX_Unmarshal

func (m *RpcMetadata) XXX_Unmarshal(b []byte) error

type Takeout

type Takeout struct {
	Id                   int64                `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	Range                *TakeoutMessageRange `protobuf:"bytes,2,opt,name=range,proto3" json:"range,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func (*Takeout) Descriptor

func (*Takeout) Descriptor() ([]byte, []int)

func (*Takeout) GetId

func (m *Takeout) GetId() int64

func (*Takeout) GetRange

func (m *Takeout) GetRange() *TakeoutMessageRange

func (*Takeout) ProtoMessage

func (*Takeout) ProtoMessage()

func (*Takeout) Reset

func (m *Takeout) Reset()

func (*Takeout) String

func (m *Takeout) String() string

func (*Takeout) XXX_DiscardUnknown

func (m *Takeout) XXX_DiscardUnknown()

func (*Takeout) XXX_Marshal

func (m *Takeout) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Takeout) XXX_Merge

func (m *Takeout) XXX_Merge(src proto.Message)

func (*Takeout) XXX_Size

func (m *Takeout) XXX_Size() int

func (*Takeout) XXX_Unmarshal

func (m *Takeout) XXX_Unmarshal(b []byte) error

type TakeoutMessageRange

type TakeoutMessageRange struct {
	MinId                int32    `protobuf:"varint,1,opt,name=min_id,json=minId,proto3" json:"min_id,omitempty"`
	MaxId                int32    `protobuf:"varint,2,opt,name=max_id,json=maxId,proto3" json:"max_id,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*TakeoutMessageRange) Descriptor

func (*TakeoutMessageRange) Descriptor() ([]byte, []int)

func (*TakeoutMessageRange) GetMaxId

func (m *TakeoutMessageRange) GetMaxId() int32

func (*TakeoutMessageRange) GetMinId

func (m *TakeoutMessageRange) GetMinId() int32

func (*TakeoutMessageRange) ProtoMessage

func (*TakeoutMessageRange) ProtoMessage()

func (*TakeoutMessageRange) Reset

func (m *TakeoutMessageRange) Reset()

func (*TakeoutMessageRange) String

func (m *TakeoutMessageRange) String() string

func (*TakeoutMessageRange) XXX_DiscardUnknown

func (m *TakeoutMessageRange) XXX_DiscardUnknown()

func (*TakeoutMessageRange) XXX_Marshal

func (m *TakeoutMessageRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TakeoutMessageRange) XXX_Merge

func (m *TakeoutMessageRange) XXX_Merge(src proto.Message)

func (*TakeoutMessageRange) XXX_Size

func (m *TakeoutMessageRange) XXX_Size() int

func (*TakeoutMessageRange) XXX_Unmarshal

func (m *TakeoutMessageRange) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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