grpcdetails

package
v0.18.7 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 3 Imported by: 0

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

func GetClientAddress(ctx context.Context) string

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

func GetMetadataValue(ctx context.Context, key string) string

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.

Jump to

Keyboard shortcuts

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