metadata

package
v0.195.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

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

View Source
var File_rpc_metadata_proto protoreflect.FileDescriptor

Functions

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,3,opt,name=client_addr,json=clientAddr,proto3" json:"client_addr,omitempty"`
	AuthId      int64  `protobuf:"varint,4,opt,name=auth_id,json=authId,proto3" json:"auth_id,omitempty"`
	SessionId   int64  `protobuf:"varint,5,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
	ReceiveTime int64  `protobuf:"varint,8,opt,name=receive_time,json=receiveTime,proto3" json:"receive_time,omitempty"`
	// 用户ID
	UserId      int64 `protobuf:"varint,11,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	ClientMsgId int64 `protobuf:"varint,12,opt,name=client_msg_id,json=clientMsgId,proto3" json:"client_msg_id,omitempty"`
	IsBot       bool  `protobuf:"varint,13,opt,name=is_bot,json=isBot,proto3" json:"is_bot,omitempty"`
	// mtproto
	Layer  int32  `protobuf:"varint,14,opt,name=layer,proto3" json:"layer,omitempty"`
	Client string `protobuf:"bytes,15,opt,name=client,proto3" json:"client,omitempty"`
	// admin
	IsAdmin bool `protobuf:"varint,16,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty"`
	// talkeout
	Takeout *Takeout `protobuf:"bytes,20,opt,name=takeout,proto3" json:"takeout,omitempty"`
	// langpack
	Langpack string `protobuf:"bytes,21,opt,name=langpack,proto3" json:"langpack,omitempty"`
	// perm_auth_key_id
	PermAuthKeyId int64 `protobuf:"varint,22,opt,name=perm_auth_key_id,json=permAuthKeyId,proto3" json:"perm_auth_key_id,omitempty"`
	// contains filtered or unexported fields
}

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 deprecated

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

Deprecated: Use RpcMetadata.ProtoReflect.Descriptor instead.

func (*RpcMetadata) GetAuthId

func (x *RpcMetadata) GetAuthId() int64

func (*RpcMetadata) GetClient

func (x *RpcMetadata) GetClient() string

func (*RpcMetadata) GetClientAddr

func (x *RpcMetadata) GetClientAddr() string

func (*RpcMetadata) GetClientMsgId

func (x *RpcMetadata) GetClientMsgId() int64

func (*RpcMetadata) GetIsAdmin

func (x *RpcMetadata) GetIsAdmin() bool

func (*RpcMetadata) GetIsBot

func (x *RpcMetadata) GetIsBot() bool

func (*RpcMetadata) GetLangpack

func (x *RpcMetadata) GetLangpack() string

func (*RpcMetadata) GetLayer

func (x *RpcMetadata) GetLayer() int32

func (*RpcMetadata) GetPermAuthKeyId added in v0.141.6

func (x *RpcMetadata) GetPermAuthKeyId() int64

func (*RpcMetadata) GetReceiveTime

func (x *RpcMetadata) GetReceiveTime() int64

func (*RpcMetadata) GetServerId

func (x *RpcMetadata) GetServerId() string

func (*RpcMetadata) GetSessionId

func (x *RpcMetadata) GetSessionId() int64

func (*RpcMetadata) GetTakeout

func (x *RpcMetadata) GetTakeout() *Takeout

func (*RpcMetadata) GetTakeoutId

func (m *RpcMetadata) GetTakeoutId() int64

func (*RpcMetadata) GetUserId

func (x *RpcMetadata) GetUserId() int64

func (*RpcMetadata) HasTakeout

func (m *RpcMetadata) HasTakeout() bool

func (*RpcMetadata) ProtoMessage

func (*RpcMetadata) ProtoMessage()

func (*RpcMetadata) ProtoReflect added in v0.179.2

func (x *RpcMetadata) ProtoReflect() protoreflect.Message

func (*RpcMetadata) Reset

func (x *RpcMetadata) Reset()

func (*RpcMetadata) String

func (x *RpcMetadata) String() string

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"`
	// contains filtered or unexported fields
}

func (*Takeout) Descriptor deprecated

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

Deprecated: Use Takeout.ProtoReflect.Descriptor instead.

func (*Takeout) GetId

func (x *Takeout) GetId() int64

func (*Takeout) GetRange

func (x *Takeout) GetRange() *TakeoutMessageRange

func (*Takeout) ProtoMessage

func (*Takeout) ProtoMessage()

func (*Takeout) ProtoReflect added in v0.179.2

func (x *Takeout) ProtoReflect() protoreflect.Message

func (*Takeout) Reset

func (x *Takeout) Reset()

func (*Takeout) String

func (x *Takeout) String() string

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"`
	// contains filtered or unexported fields
}

func (*TakeoutMessageRange) Descriptor deprecated

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

Deprecated: Use TakeoutMessageRange.ProtoReflect.Descriptor instead.

func (*TakeoutMessageRange) GetMaxId

func (x *TakeoutMessageRange) GetMaxId() int32

func (*TakeoutMessageRange) GetMinId

func (x *TakeoutMessageRange) GetMinId() int32

func (*TakeoutMessageRange) ProtoMessage

func (*TakeoutMessageRange) ProtoMessage()

func (*TakeoutMessageRange) ProtoReflect added in v0.179.2

func (x *TakeoutMessageRange) ProtoReflect() protoreflect.Message

func (*TakeoutMessageRange) Reset

func (x *TakeoutMessageRange) Reset()

func (*TakeoutMessageRange) String

func (x *TakeoutMessageRange) String() string

Jump to

Keyboard shortcuts

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