package kvdb import "context" type ( contextKey struct {} Iterator interface { Next() bool Key() string Value() []byte Close() error } DB interface { Open() error Put(string, []byte) error Get(string) ([]byte, error) Delete(string) error Iterator(string) (Iterator, error) Close() error } ) var ( ctxKey = contextKey{} ) func WithContext(c context.Context, v DB) context.Context { if c == nil { c = context.Background() } return context.WithValue(c, ctxKey, v) } func FromContext(c context.Context) DB { if c != nil { if v := c.Value(ctxKey); v != nil { if x, ok := v.(DB); ok { return x } } } return nil }