Skip to content

Commit 4c4977c

Browse files
committed
golint: comments
1 parent 6d08ca0 commit 4c4977c

39 files changed

+141
-43
lines changed

decoder_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (decCfg *DecoderConfig) UnmarshalFromString(s string, obj interface{}) erro
8989
return decCfg.Unmarshal(localStringToBytes(s), obj)
9090
}
9191

92-
// UnmarshalFromReader behave like json.Unmarshal but with a io.Reader
92+
// UnmarshalFromReader behave like json.Unmarshal but with an io.Reader
9393
func (decCfg *DecoderConfig) UnmarshalFromReader(r io.Reader, obj interface{}) error {
9494
it := decCfg.NewIterator()
9595
err := it.UnmarshalFromReader(r, obj)

decoder_config_adaptor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package jzon
22

33
// NewIterator returns a new iterator.
44
func (decCfg *DecoderConfig) NewIterator() *Iterator {
5-
it := defaultIteratorPool.BorrowIterator()
5+
it := defaultIteratorPool.borrowIterator()
66
it.cfg = decCfg
77
it.useNumber = decCfg.useNumber
88
it.disallowUnknownFields = decCfg.disallowUnknownFields
@@ -11,5 +11,5 @@ func (decCfg *DecoderConfig) NewIterator() *Iterator {
1111

1212
func (decCfg *DecoderConfig) returnIterator(it *Iterator) {
1313
it.cfg = nil
14-
defaultIteratorPool.ReturnIterator(it)
14+
defaultIteratorPool.returnIterator(it)
1515
}

encoder_config_adaptor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package jzon
22

33
// NewStreamer returns a new streamer.
44
func (encCfg *EncoderConfig) NewStreamer() *Streamer {
5-
s := defaultStreamerPool.BorrowStreamer()
5+
s := defaultStreamerPool.borrowStreamer()
66
s.cfg = encCfg
77
s.EscapeHTML(s.cfg.escapeHTML)
88
return s
99
}
1010

1111
func (encCfg *EncoderConfig) returnStreamer(s *Streamer) {
1212
s.cfg = nil
13-
defaultStreamerPool.ReturnStreamer(s)
13+
defaultStreamerPool.returnStreamer(s)
1414
}

errors_encoder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import (
44
"errors"
55
)
66

7+
// ErrNoAttachedWriter there is no writer attaching to the streamer
78
var ErrNoAttachedWriter = errors.New("no attached writer")
89

10+
// ErrFloatIsInfinity the float to write is infinity
911
var ErrFloatIsInfinity = errors.New("float is infinity")
1012

13+
// ErrFloatIsNan the float to write is NaN
1114
var ErrFloatIsNan = errors.New("float is NaN")

iterator.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ type Iterator struct {
5050
disallowUnknownFields bool
5151
}
5252

53+
// NewIterator returns a new iterator.
5354
func NewIterator() *Iterator {
5455
return DefaultDecoderConfig.NewIterator()
5556
}
5657

58+
// Release the iterator, the iterator should not be reused after call.
5759
func (it *Iterator) Release() {
5860
it.cfg.returnIterator(it)
5961
}
@@ -67,12 +69,13 @@ func (it *Iterator) reset() {
6769
it.iteratorEmbedded = iteratorEmbedded{}
6870
}
6971

70-
/*
71-
* In reset methods, explicit assignment is faster than then following
72-
* *it = Iterator{ ... }
73-
* When the above code is used, runtime.duffcopy and runtime.duffzero will be used
74-
* which will slow down our code (correct me if I am wrong)
75-
*/
72+
// Reset the iterator with an io.Reader
73+
// if the reader is nil, reset the iterator to its initial state
74+
//
75+
// In reset methods, explicit assignment is faster than then following
76+
// *it = Iterator{ ... }
77+
// When the above code is used, runtime.duffcopy and runtime.duffzero will be used
78+
// which will slow down our code (correct me if I am wrong)
7679
func (it *Iterator) Reset(r io.Reader) {
7780
switch v := r.(type) {
7881
case nil:
@@ -90,6 +93,7 @@ func (it *Iterator) Reset(r io.Reader) {
9093
it.iteratorEmbedded = iteratorEmbedded{}
9194
}
9295

96+
// ResetBytes resets iterator with a byte slice
9397
func (it *Iterator) ResetBytes(data []byte) {
9498
it.reader = nil
9599
it.buffer = data
@@ -99,6 +103,7 @@ func (it *Iterator) ResetBytes(data []byte) {
99103
it.iteratorEmbedded = iteratorEmbedded{}
100104
}
101105

106+
// Buffer returns the current slice buffer of the iterator.
102107
func (it *Iterator) Buffer() []byte {
103108
return it.buffer[it.head:it.tail]
104109
}
@@ -121,6 +126,7 @@ func (it *Iterator) errorLocation() []byte {
121126
return it.buffer[head:tail]
122127
}
123128

129+
// WrapError wraps the error with the current iterator location
124130
func (it *Iterator) WrapError(err error) *DecodeError {
125131
if e, ok := err.(*DecodeError); ok {
126132
return e
@@ -233,7 +239,7 @@ func (it *Iterator) nextToken() (ret byte, err error) {
233239
}
234240
}
235241

236-
// Read until the first valid token is found, only the whitespaces are consumed
242+
// NextValueType read until the first valid token is found, only the whitespaces are consumed
237243
func (it *Iterator) NextValueType() (ValueType, error) {
238244
v, err := it.nextToken()
239245
return valueTypeMap[v], err
@@ -254,11 +260,13 @@ func (it *Iterator) unmarshal(obj interface{}) error {
254260
return nil
255261
}
256262

263+
// Unmarshal behave like standard json.Unmarshal
257264
func (it *Iterator) Unmarshal(data []byte, obj interface{}) error {
258265
it.ResetBytes(data)
259266
return it.unmarshal(obj)
260267
}
261268

269+
// Valid behave like standard json.Valid
262270
func (it *Iterator) Valid(data []byte) bool {
263271
it.ResetBytes(data)
264272
err := it.Skip()
@@ -269,6 +277,7 @@ func (it *Iterator) Valid(data []byte) bool {
269277
return err == io.EOF
270278
}
271279

280+
// UnmarshalFromReader behave like standard json.Unmarshal but with an io.Reader
272281
func (it *Iterator) UnmarshalFromReader(r io.Reader, obj interface{}) error {
273282
it.Reset(r)
274283
return it.unmarshal(obj)

iterator_array.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package jzon
22

3-
/*
4-
* var (
5-
* more bool
6-
* err error
7-
* )
8-
* for more, err = it.ReadArray();
9-
* more;
10-
* more, err = it.ReadArrayMore() {
11-
* }
12-
* if err != nil {
13-
* // error handling
14-
* }
15-
*/
3+
// ReadArrayBegin starts to read an array
4+
//
5+
// var (
6+
// more bool
7+
// err error
8+
// )
9+
// for more, err = it.ReadArray();
10+
// more;
11+
// more, err = it.ReadArrayMore() {
12+
// }
13+
// if err != nil {
14+
// // error handling
15+
// }
1616
func (it *Iterator) ReadArrayBegin() (ret bool, err error) {
1717
c, err := it.nextToken()
1818
if err != nil {
@@ -33,6 +33,7 @@ func (it *Iterator) ReadArrayBegin() (ret bool, err error) {
3333
return true, nil
3434
}
3535

36+
// ReadArrayMore tells if there is more item to read in the array
3637
func (it *Iterator) ReadArrayMore() (ret bool, err error) {
3738
c, err := it.nextToken()
3839
if err != nil {
@@ -50,6 +51,8 @@ func (it *Iterator) ReadArrayMore() (ret bool, err error) {
5051
}
5152
}
5253

54+
// ReadArrayCB reads the array with a callback
55+
// The caller should make sure that the callback is correct
5356
func (it *Iterator) ReadArrayCB(cb func(*Iterator) error) error {
5457
c, err := it.nextToken()
5558
if err != nil {

iterator_bool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jzon
22

3+
// ReadBool reads a boolean value
34
func (it *Iterator) ReadBool() (bool, error) {
45
c, err := it.nextToken()
56
if err != nil {

iterator_float32.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strconv"
66
)
77

8+
// ReadFloat32 reads a float32 value
89
func (it *Iterator) ReadFloat32() (float32, error) {
910
c, err := it.nextToken()
1011
if err != nil {

iterator_float64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func (it *Iterator) readFloat64(c byte) (float64, error) {
2121
return f, err
2222
}
2323

24+
// ReadFloat64 reads a float64 value
2425
func (it *Iterator) ReadFloat64() (float64, error) {
2526
c, err := it.nextToken()
2627
if err != nil {

iterator_int.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func init() {
2121
}
2222
}
2323

24+
// ReadInt reads an int value
2425
func (it *Iterator) ReadInt() (int, error) {
2526
if strconv.IntSize == 32 {
2627
i, err := it.ReadInt32()
@@ -30,6 +31,7 @@ func (it *Iterator) ReadInt() (int, error) {
3031
return int(i), err
3132
}
3233

34+
// ReadUint reads an uint value
3335
func (it *Iterator) ReadUint() (uint, error) {
3436
if strconv.IntSize == 32 {
3537
u, err := it.ReadUint32()

iterator_int16.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
maxUint16Mod10 = int8(math.MaxUint16 - maxUint16Div10*10)
1313
)
1414

15+
// ReadUint16 reads an uint16 value
1516
func (it *Iterator) ReadUint16() (uint16, error) {
1617
c, err := it.nextToken()
1718
if err != nil {
@@ -92,6 +93,7 @@ func (it *Iterator) readInt16(c byte) (int16, error) {
9293
return int16(v), nil
9394
}
9495

96+
// ReadInt16 reads an int16 value
9597
func (it *Iterator) ReadInt16() (int16, error) {
9698
c, err := it.nextToken()
9799
if err != nil {

iterator_int32.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
maxUint32Mod10 = int8(math.MaxUint32 - maxUint32Div10*10)
1313
)
1414

15+
// ReadUint32 reads an uint32 value
1516
func (it *Iterator) ReadUint32() (uint32, error) {
1617
c, err := it.nextToken()
1718
if err != nil {
@@ -92,6 +93,7 @@ func (it *Iterator) readInt32(c byte) (int32, error) {
9293
return int32(v), nil
9394
}
9495

96+
// ReadInt32 reads an int32 value
9597
func (it *Iterator) ReadInt32() (int32, error) {
9698
c, err := it.nextToken()
9799
if err != nil {

iterator_int64.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
maxUint64Mod10 = int8(math.MaxUint64 - maxUint64Div10*10)
1313
)
1414

15+
// ReadUint64 reads an uint64 value
1516
func (it *Iterator) ReadUint64() (uint64, error) {
1617
c, err := it.nextToken()
1718
if err != nil {
@@ -93,6 +94,7 @@ func (it *Iterator) readInt64(c byte) (int64, error) {
9394
return int64(v), nil
9495
}
9596

97+
// ReadInt64 reads an int64 value
9698
func (it *Iterator) ReadInt64() (int64, error) {
9799
c, err := it.nextToken()
98100
if err != nil {

iterator_int8.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
maxUint8Mod10 = int8(math.MaxUint8 - maxUint8Div10*10)
1212
)
1313

14+
// ReadUint8 reads an Uint8 value
1415
func (it *Iterator) ReadUint8() (uint8, error) {
1516
c, err := it.nextToken()
1617
if err != nil {
@@ -97,6 +98,7 @@ func (it *Iterator) readInt8(c byte) (int8, error) {
9798
return int8(v), nil
9899
}
99100

101+
// ReadInt8 reads an int8 value
100102
func (it *Iterator) ReadInt8() (int8, error) {
101103
c, err := it.nextToken()
102104
if err != nil {

iterator_null.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jzon
22

3+
// ReadNull reads a nil
34
func (it *Iterator) ReadNull() error {
45
c, err := it.nextToken()
56
if err != nil {

iterator_number.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (it *Iterator) readNumberAsString(c byte) (n string, err error) {
1818
return
1919
}
2020

21+
// ReadNumber reads a Number(json.Number)
2122
func (it *Iterator) ReadNumber() (n Number, err error) {
2223
c, err := it.nextToken()
2324
if err != nil {

iterator_object.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (it *Iterator) skipObjectField() error {
4444
return nil
4545
}
4646

47+
// ReadObjectBegin starts to read an object
4748
func (it *Iterator) ReadObjectBegin() (_ bool, _ string, err error) {
4849
c, err := it.nextToken()
4950
if err != nil {
@@ -77,6 +78,7 @@ func (it *Iterator) ReadObjectBegin() (_ bool, _ string, err error) {
7778
}
7879
}
7980

81+
// ReadObjectMore tells if there is more field to read in the object
8082
func (it *Iterator) ReadObjectMore() (_ bool, _ string, err error) {
8183
c, err := it.nextToken()
8284
if err != nil {
@@ -109,6 +111,8 @@ func (it *Iterator) ReadObjectMore() (_ bool, _ string, err error) {
109111
}
110112
}
111113

114+
// ReadObjectCB reads the object with a callback
115+
// The caller should make sure that the callback is correct
112116
func (it *Iterator) ReadObjectCB(cb func(it *Iterator, field string) error) error {
113117
c, err := it.nextToken()
114118
if err != nil {

iterator_pool.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
)
66

77
var (
8-
defaultIteratorPool = NewIteratorPool()
8+
defaultIteratorPool = newIteratorPool()
99
)
1010

11-
type IteratorPool struct {
11+
type iteratorPool struct {
1212
pool sync.Pool
1313
}
1414

15-
func NewIteratorPool() *IteratorPool {
16-
return &IteratorPool{
15+
func newIteratorPool() *iteratorPool {
16+
return &iteratorPool{
1717
pool: sync.Pool{
1818
New: func() interface{} {
1919
return &Iterator{
@@ -25,12 +25,12 @@ func NewIteratorPool() *IteratorPool {
2525
}
2626
}
2727

28-
func (p *IteratorPool) BorrowIterator() *Iterator {
28+
func (p *iteratorPool) borrowIterator() *Iterator {
2929
it := p.pool.Get().(*Iterator)
3030
return it
3131
}
3232

33-
func (p *IteratorPool) ReturnIterator(it *Iterator) {
33+
func (p *iteratorPool) returnIterator(it *Iterator) {
3434
it.reset()
3535
p.pool.Put(it)
3636
}

iterator_pool_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010
func TestIteratorPool(t *testing.T) {
1111
must := require.New(t)
1212

13-
pool := NewIteratorPool()
13+
pool := newIteratorPool()
1414

1515
f := func(cb func(it *Iterator)) {
16-
it := pool.BorrowIterator()
16+
it := pool.borrowIterator()
1717
must.Nil(it.reader)
1818
must.Nil(it.buffer)
1919
must.Equal(0, it.offset)
2020
must.Equal(0, it.head)
2121
must.Equal(0, it.tail)
2222
cb(it)
23-
pool.ReturnIterator(it)
23+
pool.returnIterator(it)
2424
must.Nil(it.reader)
2525
must.Nil(it.buffer)
2626
}

0 commit comments

Comments
 (0)