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

import (
	"fmt"

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
// ErrReadOnly is used when a read-only datastructure is written to.
Jeromy's avatar
Jeromy committed
10 11
var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")

Jeromy's avatar
Jeromy committed
12 13 14
// NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService
// implementation that returns ErrReadOnly when its 'write' methods are
// invoked.
Jeromy's avatar
Jeromy committed
15 16 17 18 19 20
func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService {
	return &ComboService{
		Read:  ng,
		Write: &ErrorService{ErrReadOnly},
	}
}