rpc: remove NotifierContextKey
Context keys must have a unique type in order to prevent any unintented clashes. The code used int(1) as key. Fix it by implementing the pattern recommended by package context.
This commit is contained in:
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -62,6 +63,14 @@ type Notifier interface {
|
||||
Unsubscribe(id string) error
|
||||
}
|
||||
|
||||
type notifierKey struct{}
|
||||
|
||||
// NotifierFromContext returns the Notifier value stored in ctx, if any.
|
||||
func NotifierFromContext(ctx context.Context) (Notifier, bool) {
|
||||
n, ok := ctx.Value(notifierKey{}).(Notifier)
|
||||
return n, ok
|
||||
}
|
||||
|
||||
// Subscription defines the interface for objects that can notify subscribers
|
||||
type Subscription interface {
|
||||
// Inform client of an event
|
||||
|
Reference in New Issue
Block a user