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

import (
	"fmt"

6
	ld "gitlab.dms3.io/dms3/go-ld-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.
15
func NewReadOnlyDagService(ng ld.NodeGetter) ld.DAGService {
Jeromy's avatar
Jeromy committed
16 17 18 19 20
	return &ComboService{
		Read:  ng,
		Write: &ErrorService{ErrReadOnly},
	}
}