session.go 520 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8
package merkledag

import (
	"context"

	ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
)

Jeromy's avatar
Jeromy committed
9
// SessionMaker is an object that can generate a new fetching session.
Jeromy's avatar
Jeromy committed
10 11 12 13
type SessionMaker interface {
	Session(context.Context) ipld.NodeGetter
}

Jeromy's avatar
Jeromy committed
14 15
// NewSession returns a session backed NodeGetter if the given NodeGetter
// implements SessionMaker.
Jeromy's avatar
Jeromy committed
16 17 18 19 20 21
func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter {
	if sm, ok := g.(SessionMaker); ok {
		return sm.Session(ctx)
	}
	return g
}