Documentation ¶
Overview ¶
Package grpcdetails provides utilities for extracting detailed client information in gRPC contexts. It includes various functions to obtain additional information form gRPC or work with gRPC requests.
Example (UnaryServerInterceptor) ¶
/* You can have a middleware where from gRPC request can be extracted client details. func (m *MyMiddleware) UnaryServerInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, nextHandler grpc.UnaryHandler) (resp any, err error) { cIP := grpcdetails.GetClientAddress(ctx) cAgent := grpcdetails.GetMetadataValue(ctx, "User-Agent") // another internal code logic to use it... return nextHandler(ctx, req) } */
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientAddress ¶
GetClientAddress extracts the IP address and port of the client from the given context. It returns the address as a string in the format "ip:port" or empty string if peer information not present in the context.
func GetMetadataValue ¶
GetMetadataValue retrieves a specific value associated with a given key from the request's metadata. If the metadata is available and the key is found, the first value associated with the key is returned. If the metadata is not present or the key is not found, an empty string will be returned.
Types ¶
This section is empty.