session.go 481 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5
package merkledag

import (
	"context"

Jeromy's avatar
Jeromy committed
6
	ipld "github.com/ipfs/go-ipld-format"
Jeromy's avatar
Jeromy committed
7 8
)

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
}