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

import (
	"context"

6
	ld "gitlab.dms3.io/dms3/go-ld-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
type SessionMaker interface {
11
	Session(context.Context) ld.NodeGetter
Jeromy's avatar
Jeromy committed
12 13
}

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