remoteaddr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package remoteaddr gets the gRPC client's remote address.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAvailable is returned when the remote client address is not available
	ErrNotAvailable = errors.New("remote address is not available")
)

Functions

func GetFromContext

func GetFromContext(ctx context.Context) (net.Addr, error)

GetFromContext returns the remote address of the client calling the method, for both unary and streaming method, in a gRPC call context. ErrNotAvailable is returned if remote address is not available.

Example

ExampleGetFromContext show how to get the remote address from client

package main

import (
	"context"
	"fmt"

	"github.com/jucrouzet/grpcutils/pkg/remoteaddr"
)

// ExampleGetFromContext show how to get the remote address from client
func main() {
	addr, err := remoteaddr.GetFromContext(ctx)

	if err != nil {
		// There was an error while getting the remote address
	}
	// addr is now client's remote address
	fmt.Println(addr)
}

var ctx context.Context
Output:

func GetIPFromContext added in v1.2.0

func GetIPFromContext(ctx context.Context) (net.IP, error)

GetIPFromContext returns the remote ip of the client calling the method, for both unary and streaming method, in a gRPC call context. ErrNotAvailable is returned if remote address is not available.

Types

This section is empty.

Jump to

Keyboard shortcuts

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