Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/fcontext

fcontext

go
import "gitlab.soludian.com/soludian/fountain/libs/fcontext"

Index

func ContextValue

go
func ContextValue[T any](ctx any, key any, defaultValues ...T) T

ContextValue lấy dữ liệu từ context với key cho trước và trả về giá trị kiểu T. Nếu không tìm thấy dữ liệu, hàm sẽ trả về giá trị mặc định (nếu có).

Các tham số:

  • ctx: context có thể là fiber.Ctx hoặc context.Context.
  • key: khóa để lấy dữ liệu từ context.
  • defaultValues: giá trị mặc định nếu không tìm thấy dữ liệu trong context.

Trả về:

  • Giá trị kiểu T từ context hoặc giá trị mặc định nếu không tìm thấy dữ liệu.

Ghi chú:

  • Nếu ctx không phải là fiber.Ctx hoặc context.Context, hàm sẽ ghi log lỗi.
  • Nếu dữ liệu trong context không phải là kiểu T, hàm sẽ ghi log lỗi.

func CustomContextKeys

go
func CustomContextKeys() []string

CustomContextKeys custom context

func CustomContextKeysLength

go
func CustomContextKeysLength() int

CustomContextKeysLength custom context keys length

func EnableCPUUsage

go
func EnableCPUUsage(ctx context.Context) bool

EnableCPUUsage whether to enable cpu utilization

func GRPCGetAppName

go
func GRPCGetAppName(ctx context.Context) string

GRPCGetAppName to get the peer ip

func GRPCGetPeerIP

go
func GRPCGetPeerIP(ctx context.Context) string

GetPeerIP to get the peer ip

func GRPCGetPeerName

go
func GRPCGetPeerName(ctx context.Context) string

GRPCGetPeerName gets the peer application name

func GRPCHeaderValue

go
func GRPCHeaderValue(ctx context.Context, key string) string

GRPCHeaderValue gets the context value

func Set

go
func Set(arr []string)

Set sets the context key arr

func Value

go
func Value(ctx context.Context, key string) any

Value get data

func WithValue

go
func WithValue(ctx context.Context, key string, value any) context.Context

WithValue sets the data

type GRPCHeaderCarrier

GrpcHeaderCarrier ...

go
type GRPCHeaderCarrier metadata.MD

func (GRPCHeaderCarrier) Get

go
func (mc GRPCHeaderCarrier) Get(key string) string

Get returns the value associated with the passed key.

func (GRPCHeaderCarrier) Keys

go
func (mc GRPCHeaderCarrier) Keys() []string

Keys lists the keys stored in this carrier.

func (GRPCHeaderCarrier) Set

go
func (mc GRPCHeaderCarrier) Set(key string, value string)

Set stores the key-value pair.

Generated by gomarkdoc