diff --git a/address.go b/address.go index 2c09ef68..4f497777 100644 --- a/address.go +++ b/address.go @@ -110,9 +110,9 @@ const maxSegmentSize Size = 1<<32 - 8 func maxAllocSize() Size { if maxInt == 0x7fffffff { return Size(0x7ffffff8) - } else { - return maxSegmentSize } + + return maxSegmentSize } // DataOffset is an offset in bytes from the beginning of a struct's diff --git a/capability.go b/capability.go index fd799971..1dd6207a 100644 --- a/capability.go +++ b/capability.go @@ -23,10 +23,10 @@ func NewInterface(s *Segment, cap CapabilityID) Interface { } // ToPtr converts the interface to a generic pointer. -func (p Interface) ToPtr() Ptr { +func (i Interface) ToPtr() Ptr { return Ptr{ - seg: p.seg, - lenOrCap: uint32(p.cap), + seg: i.seg, + lenOrCap: uint32(i.cap), flags: interfacePtrFlag, } } diff --git a/capnpc-go/capnpc-go.go b/capnpc-go/capnpc-go.go index a0399164..e7004def 100644 --- a/capnpc-go/capnpc-go.go +++ b/capnpc-go/capnpc-go.go @@ -285,9 +285,8 @@ func (g *generator) Value(rel *node, t schema.Type, v schema.Value) (string, err case schema.Type_Which_bool: if v.Bool() { return "true", nil - } else { - return "false", nil } + return "false", nil case schema.Type_Which_uint8, schema.Type_Which_uint16, schema.Type_Which_uint32, schema.Type_Which_uint64: return fmt.Sprintf("uint%d(%d)", intbits(t.Which()), uintValue(v)), nil @@ -661,21 +660,21 @@ var ( } staticListTypeRefs = map[schema.Type_Which]typeRef{ // TODO(light): omitting newfunc since it doesn't have a similar type signature (no errors). - schema.Type_Which_void: typeRef{name: "VoidList", imp: capnpImportSpec}, - - schema.Type_Which_bool: typeRef{name: "BitList", newfunc: "NewBitList", imp: capnpImportSpec}, - schema.Type_Which_int8: typeRef{name: "Int8List", newfunc: "NewInt8List", imp: capnpImportSpec}, - schema.Type_Which_uint8: typeRef{name: "UInt8List", newfunc: "NewUInt8List", imp: capnpImportSpec}, - schema.Type_Which_int16: typeRef{name: "Int16List", newfunc: "NewInt16List", imp: capnpImportSpec}, - schema.Type_Which_uint16: typeRef{name: "UInt16List", newfunc: "NewUInt16List", imp: capnpImportSpec}, - schema.Type_Which_int32: typeRef{name: "Int32List", newfunc: "NewInt32List", imp: capnpImportSpec}, - schema.Type_Which_uint32: typeRef{name: "UInt32List", newfunc: "NewUInt32List", imp: capnpImportSpec}, - schema.Type_Which_int64: typeRef{name: "Int64List", newfunc: "NewInt64List", imp: capnpImportSpec}, - schema.Type_Which_uint64: typeRef{name: "UInt64List", newfunc: "NewUInt64List", imp: capnpImportSpec}, - schema.Type_Which_float32: typeRef{name: "Float32List", newfunc: "NewFloat32List", imp: capnpImportSpec}, - schema.Type_Which_float64: typeRef{name: "Float64List", newfunc: "NewFloat64List", imp: capnpImportSpec}, - schema.Type_Which_text: typeRef{name: "TextList", newfunc: "NewTextList", imp: capnpImportSpec}, - schema.Type_Which_data: typeRef{name: "DataList", newfunc: "NewDataList", imp: capnpImportSpec}, + schema.Type_Which_void: {name: "VoidList", imp: capnpImportSpec}, + + schema.Type_Which_bool: {name: "BitList", newfunc: "NewBitList", imp: capnpImportSpec}, + schema.Type_Which_int8: {name: "Int8List", newfunc: "NewInt8List", imp: capnpImportSpec}, + schema.Type_Which_uint8: {name: "UInt8List", newfunc: "NewUInt8List", imp: capnpImportSpec}, + schema.Type_Which_int16: {name: "Int16List", newfunc: "NewInt16List", imp: capnpImportSpec}, + schema.Type_Which_uint16: {name: "UInt16List", newfunc: "NewUInt16List", imp: capnpImportSpec}, + schema.Type_Which_int32: {name: "Int32List", newfunc: "NewInt32List", imp: capnpImportSpec}, + schema.Type_Which_uint32: {name: "UInt32List", newfunc: "NewUInt32List", imp: capnpImportSpec}, + schema.Type_Which_int64: {name: "Int64List", newfunc: "NewInt64List", imp: capnpImportSpec}, + schema.Type_Which_uint64: {name: "UInt64List", newfunc: "NewUInt64List", imp: capnpImportSpec}, + schema.Type_Which_float32: {name: "Float32List", newfunc: "NewFloat32List", imp: capnpImportSpec}, + schema.Type_Which_float64: {name: "Float64List", newfunc: "NewFloat64List", imp: capnpImportSpec}, + schema.Type_Which_text: {name: "TextList", newfunc: "NewTextList", imp: capnpImportSpec}, + schema.Type_Which_data: {name: "DataList", newfunc: "NewDataList", imp: capnpImportSpec}, } ) diff --git a/internal/cmd/mktemplates/mktemplates.go b/internal/cmd/mktemplates/mktemplates.go index 4a90cb2c..a2871bdc 100644 --- a/internal/cmd/mktemplates/mktemplates.go +++ b/internal/cmd/mktemplates/mktemplates.go @@ -1,4 +1,6 @@ +//go:build mktemplates // +build mktemplates + // Build tag so that users who run `go get capnproto.org/go/capnp/v3/...` don't install this command. // cd internal/cmd/mktemplates && go build -tags=mktemplates diff --git a/internal/fuzztest/fuzztest.go b/internal/fuzztest/fuzztest.go index 3737ee96..160d95f0 100644 --- a/internal/fuzztest/fuzztest.go +++ b/internal/fuzztest/fuzztest.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz // Fuzz test harness. To run: diff --git a/internal/nodemap/nodemap.go b/internal/nodemap/nodemap.go index 9b8bff2b..b7ea75c8 100644 --- a/internal/nodemap/nodemap.go +++ b/internal/nodemap/nodemap.go @@ -21,6 +21,7 @@ func (m *Map) registry() *schemas.Registry { return &schemas.DefaultRegistry } +// UseRegistry assigns 'reg' to 'm' and initializes the nodes map. func (m *Map) UseRegistry(reg *schemas.Registry) { m.reg = reg m.nodes = make(map[uint64]schema.Node) diff --git a/internal/packed/discard.go b/internal/packed/discard.go index 6bf54628..5bec2c7e 100644 --- a/internal/packed/discard.go +++ b/internal/packed/discard.go @@ -1,3 +1,4 @@ +//go:build go1.5 // +build go1.5 package packed diff --git a/internal/packed/discard_go14.go b/internal/packed/discard_go14.go index a42c391f..722111ed 100644 --- a/internal/packed/discard_go14.go +++ b/internal/packed/discard_go14.go @@ -1,3 +1,4 @@ +//go:build !go1.5 // +build !go1.5 package packed diff --git a/internal/packed/fuzz.go b/internal/packed/fuzz.go index 61114ae6..2c52161d 100644 --- a/internal/packed/fuzz.go +++ b/internal/packed/fuzz.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz // Fuzz test harness. To run: diff --git a/list.go b/list.go index cf073b8d..e19ac646 100644 --- a/list.go +++ b/list.go @@ -352,7 +352,7 @@ func NewTextList(s *Segment, n int32) (TextList, error) { if err != nil { return TextList{}, err } - return TextList{pl.List}, nil + return TextList(pl), nil } // At returns the i'th string in the list. @@ -426,7 +426,7 @@ func NewDataList(s *Segment, n int32) (DataList, error) { if err != nil { return DataList{}, err } - return DataList{pl.List}, nil + return DataList(pl), nil } // At returns the i'th data in the list. diff --git a/message_go18.go b/message_go18.go index d2853072..fcb97906 100644 --- a/message_go18.go +++ b/message_go18.go @@ -1,3 +1,4 @@ +//go:build go1.8 // +build go1.8 package capnp diff --git a/message_other.go b/message_other.go index ba1ab667..0f94c6e7 100644 --- a/message_other.go +++ b/message_other.go @@ -1,3 +1,4 @@ +//go:build !go1.8 // +build !go1.8 package capnp diff --git a/msgp_bench_gen_test.go b/msgp_bench_gen_test.go index c4425ec2..b45b877c 100644 --- a/msgp_bench_gen_test.go +++ b/msgp_bench_gen_test.go @@ -1,3 +1,4 @@ +//go:build msgpbench // +build msgpbench package capnp_test diff --git a/msgp_bench_test.go b/msgp_bench_test.go index f336c570..4a4bb806 100644 --- a/msgp_bench_test.go +++ b/msgp_bench_test.go @@ -1,4 +1,6 @@ +//go:build msgpbench // +build msgpbench + //go:generate msgp -tests=false -o msgp_bench_gen_test.go //msgp:Tuple Event diff --git a/pogs/insert.go b/pogs/insert.go index e79f0021..eca07ad8 100644 --- a/pogs/insert.go +++ b/pogs/insert.go @@ -170,9 +170,9 @@ func (ins *inserter) insertField(s capnp.Struct, f schema.Field, val reflect.Val } if val.Kind() == reflect.String { return s.SetText(off, val.String()) - } else { - return s.SetTextFromBytes(off, val.Bytes()) } + return s.SetTextFromBytes(off, val.Bytes()) + case schema.Type_Which_data: b := val.Bytes() if b == nil && !isEmptyValue(dv) { diff --git a/pointer.go b/pointer.go index 8548bdd1..8f8e27b9 100644 --- a/pointer.go +++ b/pointer.go @@ -144,7 +144,7 @@ func (p Ptr) text() (b []byte, ok bool) { // Text must be null-terminated. return nil, false } - return b[:len(b)-1 : len(b)], true + return b[: len(b)-1 : len(b)], true } // Data attempts to convert p into Data, returning nil if p is not a diff --git a/rpc/answer.go b/rpc/answer.go index 8eff4001..f6a99ea3 100644 --- a/rpc/answer.go +++ b/rpc/answer.go @@ -279,7 +279,7 @@ func (ans *answer) sendException(e error) releaseList { if ans.flags&finishReceived == 0 { return nil } - // destory will never return an error because sendException does + // destroy will never return an error because sendException does // create any exports. rl, _ := ans.destroy() ans.c.mu.Unlock() diff --git a/rpc/rpc.go b/rpc/rpc.go index 34466fbb..6d864ae9 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -123,9 +123,8 @@ type Options struct { AbortTimeout time.Duration } -// A type that implements ErrorReporter can receive errors from a Conn. -// ReportError should be quick to return and should not use the Conn -// that it is attached to. +// ErrorReporter can receive errors from a Conn. ReportError should be quick +// to return and should not use the Conn that it is attached to. type ErrorReporter interface { ReportError(error) } diff --git a/rpc/transport_go19_test.go b/rpc/transport_go19_test.go index c74e3558..d90c7a53 100644 --- a/rpc/transport_go19_test.go +++ b/rpc/transport_go19_test.go @@ -1,4 +1,5 @@ -//+build go1.9 +//go:build go1.9 +// +build go1.9 package rpc_test