Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f18b837

Browse files
committedAug 9, 2018
Rename Format to Builder.
1 parent 88cd5dc commit f18b837

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed
 

‎format.go ‎builder.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import (
44
mh "github.com/multiformats/go-multihash"
55
)
66

7-
type Format interface {
7+
type Builder interface {
88
Sum(data []byte) (*Cid, error)
99
GetCodec() uint64
10-
WithCodec(uint64) Format
10+
WithCodec(uint64) Builder
1111
}
1212

13-
type FormatV0 struct{}
13+
type V0Builder struct{}
1414

15-
type FormatV1 struct {
15+
type V1Builder struct {
1616
Codec uint64
1717
HashFun uint64
1818
HashLen int // HashLen <= 0 means the default length
1919
}
2020

21-
func PrefixToFormat(p Prefix) Format {
21+
func PrefixToBuilder(p Prefix) Builder {
2222
if p.Version == 0 {
23-
return FormatV0{}
23+
return V0Builder{}
2424
}
2525
mhLen := p.MhLength
2626
if p.MhType == mh.ID {
@@ -29,7 +29,7 @@ func PrefixToFormat(p Prefix) Format {
2929
if mhLen < 0 {
3030
mhLen = 0
3131
}
32-
return FormatV1{
32+
return V1Builder{
3333
Codec: p.Codec,
3434
HashFun: p.MhType,
3535
HashLen: mhLen,
@@ -40,7 +40,7 @@ func (p Prefix) GetCodec() uint64 {
4040
return p.Codec
4141
}
4242

43-
func (p Prefix) WithCodec(c uint64) Format {
43+
func (p Prefix) WithCodec(c uint64) Builder {
4444
if c == p.Codec {
4545
return p
4646
}
@@ -51,26 +51,26 @@ func (p Prefix) WithCodec(c uint64) Format {
5151
return p
5252
}
5353

54-
func (p FormatV0) Sum(data []byte) (*Cid, error) {
54+
func (p V0Builder) Sum(data []byte) (*Cid, error) {
5555
hash, err := mh.Sum(data, mh.SHA2_256, -1)
5656
if err != nil {
5757
return nil, err
5858
}
5959
return NewCidV0(hash), nil
6060
}
6161

62-
func (p FormatV0) GetCodec() uint64 {
62+
func (p V0Builder) GetCodec() uint64 {
6363
return DagProtobuf
6464
}
6565

66-
func (p FormatV0) WithCodec(c uint64) Format {
66+
func (p V0Builder) WithCodec(c uint64) Builder {
6767
if c == DagProtobuf {
6868
return p
6969
}
70-
return FormatV1{Codec: c, HashFun: mh.SHA2_256}
70+
return V1Builder{Codec: c, HashFun: mh.SHA2_256}
7171
}
7272

73-
func (p FormatV1) Sum(data []byte) (*Cid, error) {
73+
func (p V1Builder) Sum(data []byte) (*Cid, error) {
7474
mhLen := p.HashLen
7575
if mhLen <= 0 {
7676
mhLen = -1
@@ -82,11 +82,11 @@ func (p FormatV1) Sum(data []byte) (*Cid, error) {
8282
return NewCidV1(p.Codec, hash), nil
8383
}
8484

85-
func (p FormatV1) GetCodec() uint64 {
85+
func (p V1Builder) GetCodec() uint64 {
8686
return p.Codec
8787
}
8888

89-
func (p FormatV1) WithCodec(c uint64) Format {
89+
func (p V1Builder) WithCodec(c uint64) Builder {
9090
p.Codec = c
9191
return p
9292
}

‎format_test.go ‎builder_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestFormatV1(t *testing.T) {
1010
data := []byte("this is some test content")
1111

1212
// Construct c1
13-
format := FormatV1{Codec: DagCBOR, HashFun: mh.SHA2_256}
13+
format := V1Builder{Codec: DagCBOR, HashFun: mh.SHA2_256}
1414
c1, err := format.Sum(data)
1515
if err != nil {
1616
t.Fatal(err)
@@ -35,7 +35,7 @@ func TestFormatV0(t *testing.T) {
3535
data := []byte("this is some test content")
3636

3737
// Construct c1
38-
format := FormatV0{}
38+
format := V0Builder{}
3939
c1, err := format.Sum(data)
4040
if err != nil {
4141
t.Fatal(err)
@@ -55,4 +55,3 @@ func TestFormatV0(t *testing.T) {
5555
t.Fatal("prefixes mismatch")
5656
}
5757
}
58-

0 commit comments

Comments
 (0)