good morning!!!!

Skip to content
Snippets Groups Projects
util.go 618 B
Newer Older
a's avatar
a committed
package server

import (
	"context"

a's avatar
a committed
	"gfx.cafe/open/jrpc/pkg/jsonrpc"
a's avatar
a committed
)

type peerInfoContextKey struct{}

// PeerInfoFromContext returns information about the client's network connection.
// Use this with the context passed to RPC method handler functions.
//
// The zero value is returned if no connection info is present in ctx.
a's avatar
a committed
func PeerInfoFromContext(ctx context.Context) jsonrpc.PeerInfo {
	info, _ := ctx.Value(peerInfoContextKey{}).(jsonrpc.PeerInfo)
a's avatar
a committed
	return info
}
a's avatar
a committed
func ContextWithPeerInfo(ctx context.Context, c jsonrpc.PeerInfo) context.Context {
a's avatar
a committed
	return context.WithValue(ctx, peerInfoContextKey{}, c)
}