Import path:
gitlab.soludian.com/soludian/fountain/libs/fcontext
fcontext
go
import "gitlab.soludian.com/soludian/fountain/libs/fcontext"Index
- func ContextValue[T any](ctx any, key any, defaultValues ...T) T
- func CustomContextKeys() []string
- func CustomContextKeysLength() int
- func EnableCPUUsage(ctx context.Context) bool
- func GRPCGetAppName(ctx context.Context) string
- func GRPCGetPeerIP(ctx context.Context) string
- func GRPCGetPeerName(ctx context.Context) string
- func GRPCHeaderValue(ctx context.Context, key string) string
- func Set(arr []string)
- func Value(ctx context.Context, key string) any
- func WithValue(ctx context.Context, key string, value any) context.Context
- type GRPCHeaderCarrier
func ContextValue
go
func ContextValue[T any](ctx any, key any, defaultValues ...T) TContextValue 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() []stringCustomContextKeys custom context
func CustomContextKeysLength
go
func CustomContextKeysLength() intCustomContextKeysLength custom context keys length
func EnableCPUUsage
go
func EnableCPUUsage(ctx context.Context) boolEnableCPUUsage whether to enable cpu utilization
func GRPCGetAppName
go
func GRPCGetAppName(ctx context.Context) stringGRPCGetAppName to get the peer ip
func GRPCGetPeerIP
go
func GRPCGetPeerIP(ctx context.Context) stringGetPeerIP to get the peer ip
func GRPCGetPeerName
go
func GRPCGetPeerName(ctx context.Context) stringGRPCGetPeerName gets the peer application name
func GRPCHeaderValue
go
func GRPCHeaderValue(ctx context.Context, key string) stringGRPCHeaderValue 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) anyValue get data
func WithValue
go
func WithValue(ctx context.Context, key string, value any) context.ContextWithValue sets the data
type GRPCHeaderCarrier
GrpcHeaderCarrier ...
go
type GRPCHeaderCarrier metadata.MDfunc (GRPCHeaderCarrier) Get
go
func (mc GRPCHeaderCarrier) Get(key string) stringGet returns the value associated with the passed key.
func (GRPCHeaderCarrier) Keys
go
func (mc GRPCHeaderCarrier) Keys() []stringKeys 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