@@ -89,7 +89,7 @@ const (
89
89
BinaryUserDefined byte = 0x80
90
90
)
91
91
92
- // A value implementing the bson.Getter interface will have its GetBSON
92
+ // Getter interface: a value implementing the bson.Getter interface will have its GetBSON
93
93
// method called when the given value has to be marshalled, and the result
94
94
// of this method will be marshaled in place of the actual object.
95
95
//
@@ -99,12 +99,12 @@ type Getter interface {
99
99
GetBSON () (interface {}, error )
100
100
}
101
101
102
- // A value implementing the bson.Setter interface will receive the BSON
102
+ // Setter interface: a value implementing the bson.Setter interface will receive the BSON
103
103
// value via the SetBSON method during unmarshaling, and the object
104
104
// itself will not be changed as usual.
105
105
//
106
106
// If setting the value works, the method should return nil or alternatively
107
- // bson.SetZero to set the respective field to its zero value (nil for
107
+ // bson.ErrSetZero to set the respective field to its zero value (nil for
108
108
// pointer types). If SetBSON returns a value of type bson.TypeError, the
109
109
// BSON value will be omitted from a map or slice being decoded and the
110
110
// unmarshalling will continue. If it returns any other non-nil error, the
@@ -130,10 +130,10 @@ type Setter interface {
130
130
SetBSON (raw Raw ) error
131
131
}
132
132
133
- // SetZero may be returned from a SetBSON method to have the value set to
133
+ // ErrSetZero may be returned from a SetBSON method to have the value set to
134
134
// its respective zero value. When used in pointer values, this will set the
135
135
// field to nil rather than to the pre-allocated value.
136
- var SetZero = errors .New ("set to zero" )
136
+ var ErrSetZero = errors .New ("set to zero" )
137
137
138
138
// M is a convenient alias for a map[string]interface{} map, useful for
139
139
// dealing with BSON in a native way. For instance:
@@ -189,7 +189,7 @@ type Raw struct {
189
189
// documents in general.
190
190
type RawD []RawDocElem
191
191
192
- // See the RawD type.
192
+ // RawDocElem elements of RawD type.
193
193
type RawDocElem struct {
194
194
Name string
195
195
Value Raw
@@ -199,7 +199,7 @@ type RawDocElem struct {
199
199
// long. MongoDB objects by default have such a property set in their "_id"
200
200
// property.
201
201
//
202
- // http://www.mongodb.org/display/DOCS/Object+IDs
202
+ // http://www.mongodb.org/display/DOCS/Object+Ids
203
203
type ObjectId string
204
204
205
205
// ObjectIdHex returns an ObjectId from the provided hex representation.
@@ -225,7 +225,7 @@ func IsObjectIdHex(s string) bool {
225
225
226
226
// objectIdCounter is atomically incremented when generating a new ObjectId
227
227
// using NewObjectId() function. It's used as a counter part of an id.
228
- var objectIdCounter uint32 = readRandomUint32 ()
228
+ var objectIdCounter = readRandomUint32 ()
229
229
230
230
// readRandomUint32 returns a random objectIdCounter.
231
231
func readRandomUint32 () uint32 {
@@ -333,12 +333,12 @@ func (id *ObjectId) UnmarshalJSON(data []byte) error {
333
333
return nil
334
334
}
335
335
if len (data ) != 26 || data [0 ] != '"' || data [25 ] != '"' {
336
- return errors . New ( fmt .Sprintf ("invalid ObjectId in JSON: %s" , string (data ) ))
336
+ return fmt .Errorf ("invalid ObjectId in JSON: %s" , string (data ))
337
337
}
338
338
var buf [12 ]byte
339
339
_ , err := hex .Decode (buf [:], data [1 :25 ])
340
340
if err != nil {
341
- return errors . New ( fmt .Sprintf ("invalid ObjectId in JSON: %s (%s)" , string (data ), err ) )
341
+ return fmt .Errorf ("invalid ObjectId in JSON: %s (%s)" , string (data ), err )
342
342
}
343
343
* id = ObjectId (string (buf [:]))
344
344
return nil
@@ -604,12 +604,12 @@ func Unmarshal(in []byte, out interface{}) (err error) {
604
604
d := newDecoder (in )
605
605
d .readDocTo (v )
606
606
if d .i < len (d .in ) {
607
- return errors .New ("Document is corrupted" )
607
+ return errors .New ("document is corrupted" )
608
608
}
609
609
case reflect .Struct :
610
- return errors .New ("Unmarshal can't deal with struct values. Use a pointer. " )
610
+ return errors .New ("unmarshal can't deal with struct values. Use a pointer" )
611
611
default :
612
- return errors .New ("Unmarshal needs a map or a pointer to a struct. " )
612
+ return errors .New ("unmarshal needs a map or a pointer to a struct" )
613
613
}
614
614
return nil
615
615
}
@@ -633,13 +633,15 @@ func (raw Raw) Unmarshal(out interface{}) (err error) {
633
633
return & TypeError {v .Type (), raw .Kind }
634
634
}
635
635
case reflect .Struct :
636
- return errors .New ("Raw Unmarshal can't deal with struct values. Use a pointer. " )
636
+ return errors .New ("raw Unmarshal can't deal with struct values. Use a pointer" )
637
637
default :
638
- return errors .New ("Raw Unmarshal needs a map or a valid pointer. " )
638
+ return errors .New ("raw Unmarshal needs a map or a valid pointer" )
639
639
}
640
640
return nil
641
641
}
642
642
643
+ // TypeError store details for type error occuring
644
+ // during unmarshaling
643
645
type TypeError struct {
644
646
Type reflect.Type
645
647
Kind byte
0 commit comments