From 372b8d8cbff9f85ed7cef0068df15d451d1dc213 Mon Sep 17 00:00:00 2001 From: benjirewis Date: Thu, 8 Sep 2022 13:34:54 -0400 Subject: [PATCH] Run fmt --- bson/bson.go | 6 +- bson/bsoncodec/doc.go | 12 +- bson/bsoncodec/registry.go | 1 + bson/bsoncodec/struct_tag_parser.go | 42 +++---- bson/doc.go | 109 +++++++++--------- bson/mgocompat/doc.go | 45 ++++---- bson/mgocompat/setter_getter.go | 9 +- bson/primitive/decimal.go | 7 +- bson/primitive/primitive.go | 6 +- event/doc.go | 58 +++++----- internal/error.go | 2 +- mongo/database.go | 2 +- mongo/doc.go | 117 ++++++++++---------- mongo/errors.go | 3 +- mongo/gridfs/doc.go | 26 +++-- mongo/mongo.go | 9 +- mongo/options/autoencryptionoptions.go | 2 +- mongo/options/clientencryptionoptions.go | 12 +- mongo/options/datakeyoptions.go | 42 ++++--- x/bsonx/bsoncore/document_sequence.go | 4 +- x/mongo/driver/operation/drop_indexes.go | 1 - x/mongo/driver/operation/find_and_modify.go | 1 - 22 files changed, 262 insertions(+), 254 deletions(-) diff --git a/bson/bson.go b/bson/bson.go index 95ffc1078d..a0d8185826 100644 --- a/bson/bson.go +++ b/bson/bson.go @@ -27,7 +27,7 @@ type Zeroer interface { // // Example usage: // -// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} +// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} type D = primitive.D // E represents a BSON element for a D. It is usually used inside a D. @@ -39,12 +39,12 @@ type E = primitive.E // // Example usage: // -// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} +// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} type M = primitive.M // An A is an ordered representation of a BSON array. // // Example usage: // -// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}} +// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}} type A = primitive.A diff --git a/bson/bsoncodec/doc.go b/bson/bsoncodec/doc.go index b0ae0e23ff..5f903ebea6 100644 --- a/bson/bsoncodec/doc.go +++ b/bson/bsoncodec/doc.go @@ -17,7 +17,7 @@ // 2) A Registry that holds these ValueEncoders and ValueDecoders and provides methods for // retrieving them. // -// ValueEncoders and ValueDecoders +// # ValueEncoders and ValueDecoders // // The ValueEncoder interface is implemented by types that can encode a provided Go type to BSON. // The value to encode is provided as a reflect.Value and a bsonrw.ValueWriter is used within the @@ -31,7 +31,7 @@ // allow the use of a function with the correct signature as a ValueDecoder. A DecodeContext // instance is provided and serves similar functionality to the EncodeContext. // -// Registry and RegistryBuilder +// # Registry and RegistryBuilder // // A Registry is an immutable store for ValueEncoders, ValueDecoders, and a type map. See the Registry type // documentation for examples of registering various custom encoders and decoders. A Registry can be constructed using a @@ -53,15 +53,15 @@ // values decode as Go int32 and int64 instances, respectively, when decoding into a bson.D. The following code would // change the behavior so these values decode as Go int instances instead: // -// intType := reflect.TypeOf(int(0)) -// registryBuilder.RegisterTypeMapEntry(bsontype.Int32, intType).RegisterTypeMapEntry(bsontype.Int64, intType) +// intType := reflect.TypeOf(int(0)) +// registryBuilder.RegisterTypeMapEntry(bsontype.Int32, intType).RegisterTypeMapEntry(bsontype.Int64, intType) // // 4. Kind encoder/decoders - These can be registered using the RegisterDefaultEncoder and RegisterDefaultDecoder // methods. The registered codec will be invoked when encoding or decoding values whose reflect.Kind matches the // registered reflect.Kind as long as the value's type doesn't match a registered type or hook encoder/decoder first. // These methods should be used to change the behavior for all values for a specific kind. // -// Registry Lookup Procedure +// # Registry Lookup Procedure // // When looking up an encoder in a Registry, the precedence rules are as follows: // @@ -79,7 +79,7 @@ // rules apply for decoders, with the exception that an error of type ErrNoDecoder will be returned if no decoder is // found. // -// DefaultValueEncoders and DefaultValueDecoders +// # DefaultValueEncoders and DefaultValueDecoders // // The DefaultValueEncoders and DefaultValueDecoders types provide a full set of ValueEncoders and // ValueDecoders for handling a wide range of Go types, including all of the types within the diff --git a/bson/bsoncodec/registry.go b/bson/bsoncodec/registry.go index f6f3800d40..80644023c2 100644 --- a/bson/bsoncodec/registry.go +++ b/bson/bsoncodec/registry.go @@ -254,6 +254,7 @@ func (rb *RegistryBuilder) RegisterDefaultDecoder(kind reflect.Kind, dec ValueDe // By default, BSON documents will decode into interface{} values as bson.D. To change the default type for BSON // documents, a type map entry for bsontype.EmbeddedDocument should be registered. For example, to force BSON documents // to decode to bson.Raw, use the following code: +// // rb.RegisterTypeMapEntry(bsontype.EmbeddedDocument, reflect.TypeOf(bson.Raw{})) func (rb *RegistryBuilder) RegisterTypeMapEntry(bt bsontype.Type, rt reflect.Type) *RegistryBuilder { rb.typeMap[bt] = rt diff --git a/bson/bsoncodec/struct_tag_parser.go b/bson/bsoncodec/struct_tag_parser.go index 6f406c1623..62708c5c74 100644 --- a/bson/bsoncodec/struct_tag_parser.go +++ b/bson/bsoncodec/struct_tag_parser.go @@ -34,21 +34,21 @@ func (stpf StructTagParserFunc) ParseStructTags(sf reflect.StructField) (StructT // // The properties are defined below: // -// OmitEmpty Only include the field if it's not set to the zero value for the type or to -// empty slices or maps. +// OmitEmpty Only include the field if it's not set to the zero value for the type or to +// empty slices or maps. // -// MinSize Marshal an integer of a type larger than 32 bits value as an int32, if that's -// feasible while preserving the numeric value. +// MinSize Marshal an integer of a type larger than 32 bits value as an int32, if that's +// feasible while preserving the numeric value. // -// Truncate When unmarshaling a BSON double, it is permitted to lose precision to fit within -// a float32. +// Truncate When unmarshaling a BSON double, it is permitted to lose precision to fit within +// a float32. // -// Inline Inline the field, which must be a struct or a map, causing all of its fields -// or keys to be processed as if they were part of the outer struct. For maps, -// keys must not conflict with the bson keys of other struct fields. +// Inline Inline the field, which must be a struct or a map, causing all of its fields +// or keys to be processed as if they were part of the outer struct. For maps, +// keys must not conflict with the bson keys of other struct fields. // -// Skip This struct field should be skipped. This is usually denoted by parsing a "-" -// for the name. +// Skip This struct field should be skipped. This is usually denoted by parsing a "-" +// for the name. // // TODO(skriptble): Add tags for undefined as nil and for null as nil. type StructTags struct { @@ -67,20 +67,20 @@ type StructTags struct { // If there is no name in the struct tag fields, the struct field name is lowercased. // The tag formats accepted are: // -// "[][,[,]]" +// "[][,[,]]" // -// `(...) bson:"[][,[,]]" (...)` +// `(...) bson:"[][,[,]]" (...)` // // An example: // -// type T struct { -// A bool -// B int "myb" -// C string "myc,omitempty" -// D string `bson:",omitempty" json:"jsonkey"` -// E int64 ",minsize" -// F int64 "myf,omitempty,minsize" -// } +// type T struct { +// A bool +// B int "myb" +// C string "myc,omitempty" +// D string `bson:",omitempty" json:"jsonkey"` +// E int64 ",minsize" +// F int64 "myf,omitempty,minsize" +// } // // A struct tag either consisting entirely of '-' or with a bson key with a // value consisting entirely of '-' will return a StructTags with Skip true and diff --git a/bson/doc.go b/bson/doc.go index 5e3825a231..0134006d8e 100644 --- a/bson/doc.go +++ b/bson/doc.go @@ -9,21 +9,22 @@ // The BSON library handles marshalling and unmarshalling of values through a configurable codec system. For a description // of the codec system and examples of registering custom codecs, see the bsoncodec package. // -// Raw BSON +// # Raw BSON // // The Raw family of types is used to validate and retrieve elements from a slice of bytes. This // type is most useful when you want do lookups on BSON bytes without unmarshaling it into another // type. // // Example: -// var raw bson.Raw = ... // bytes from somewhere -// err := raw.Validate() -// if err != nil { return err } -// val := raw.Lookup("foo") -// i32, ok := val.Int32OK() -// // do something with i32... // -// Native Go Types +// var raw bson.Raw = ... // bytes from somewhere +// err := raw.Validate() +// if err != nil { return err } +// val := raw.Lookup("foo") +// i32, ok := val.Int32OK() +// // do something with i32... +// +// # Native Go Types // // The D and M types defined in this package can be used to build representations of BSON using native Go types. D is a // slice and M is a map. For more information about the use cases for these types, see the documentation on the type @@ -32,63 +33,64 @@ // Note that a D should not be constructed with duplicate key names, as that can cause undefined server behavior. // // Example: -// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} -// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} +// +// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} +// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} // // When decoding BSON to a D or M, the following type mappings apply when unmarshalling: // -// 1. BSON int32 unmarshals to an int32. -// 2. BSON int64 unmarshals to an int64. -// 3. BSON double unmarshals to a float64. -// 4. BSON string unmarshals to a string. -// 5. BSON boolean unmarshals to a bool. -// 6. BSON embedded document unmarshals to the parent type (i.e. D for a D, M for an M). -// 7. BSON array unmarshals to a bson.A. -// 8. BSON ObjectId unmarshals to a primitive.ObjectID. -// 9. BSON datetime unmarshals to a primitive.DateTime. -// 10. BSON binary unmarshals to a primitive.Binary. -// 11. BSON regular expression unmarshals to a primitive.Regex. -// 12. BSON JavaScript unmarshals to a primitive.JavaScript. -// 13. BSON code with scope unmarshals to a primitive.CodeWithScope. -// 14. BSON timestamp unmarshals to an primitive.Timestamp. -// 15. BSON 128-bit decimal unmarshals to an primitive.Decimal128. -// 16. BSON min key unmarshals to an primitive.MinKey. -// 17. BSON max key unmarshals to an primitive.MaxKey. -// 18. BSON undefined unmarshals to a primitive.Undefined. -// 19. BSON null unmarshals to nil. -// 20. BSON DBPointer unmarshals to a primitive.DBPointer. -// 21. BSON symbol unmarshals to a primitive.Symbol. +// 1. BSON int32 unmarshals to an int32. +// 2. BSON int64 unmarshals to an int64. +// 3. BSON double unmarshals to a float64. +// 4. BSON string unmarshals to a string. +// 5. BSON boolean unmarshals to a bool. +// 6. BSON embedded document unmarshals to the parent type (i.e. D for a D, M for an M). +// 7. BSON array unmarshals to a bson.A. +// 8. BSON ObjectId unmarshals to a primitive.ObjectID. +// 9. BSON datetime unmarshals to a primitive.DateTime. +// 10. BSON binary unmarshals to a primitive.Binary. +// 11. BSON regular expression unmarshals to a primitive.Regex. +// 12. BSON JavaScript unmarshals to a primitive.JavaScript. +// 13. BSON code with scope unmarshals to a primitive.CodeWithScope. +// 14. BSON timestamp unmarshals to an primitive.Timestamp. +// 15. BSON 128-bit decimal unmarshals to an primitive.Decimal128. +// 16. BSON min key unmarshals to an primitive.MinKey. +// 17. BSON max key unmarshals to an primitive.MaxKey. +// 18. BSON undefined unmarshals to a primitive.Undefined. +// 19. BSON null unmarshals to nil. +// 20. BSON DBPointer unmarshals to a primitive.DBPointer. +// 21. BSON symbol unmarshals to a primitive.Symbol. // // The above mappings also apply when marshalling a D or M to BSON. Some other useful marshalling mappings are: // -// 1. time.Time marshals to a BSON datetime. -// 2. int8, int16, and int32 marshal to a BSON int32. -// 3. int marshals to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, inclusive, and a BSON int64 -// otherwise. -// 4. int64 marshals to BSON int64. -// 5. uint8 and uint16 marshal to a BSON int32. -// 6. uint, uint32, and uint64 marshal to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, -// inclusive, and BSON int64 otherwise. -// 7. BSON null and undefined values will unmarshal into the zero value of a field (e.g. unmarshalling a BSON null or -// undefined value into a string will yield the empty string.). +// 1. time.Time marshals to a BSON datetime. +// 2. int8, int16, and int32 marshal to a BSON int32. +// 3. int marshals to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, inclusive, and a BSON int64 +// otherwise. +// 4. int64 marshals to BSON int64. +// 5. uint8 and uint16 marshal to a BSON int32. +// 6. uint, uint32, and uint64 marshal to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, +// inclusive, and BSON int64 otherwise. +// 7. BSON null and undefined values will unmarshal into the zero value of a field (e.g. unmarshalling a BSON null or +// undefined value into a string will yield the empty string.). // -// Structs +// # Structs // // Structs can be marshalled/unmarshalled to/from BSON or Extended JSON. When transforming structs to/from BSON or Extended // JSON, the following rules apply: // -// 1. Only exported fields in structs will be marshalled or unmarshalled. +// 1. Only exported fields in structs will be marshalled or unmarshalled. // -// 2. When marshalling a struct, each field will be lowercased to generate the key for the corresponding BSON element. +// 2. When marshalling a struct, each field will be lowercased to generate the key for the corresponding BSON element. // For example, a struct field named "Foo" will generate key "foo". This can be overridden via a struct tag (e.g. // `bson:"fooField"` to generate key "fooField" instead). // -// 3. An embedded struct field is marshalled as a subdocument. The key will be the lowercased name of the field's type. +// 3. An embedded struct field is marshalled as a subdocument. The key will be the lowercased name of the field's type. // -// 4. A pointer field is marshalled as the underlying type if the pointer is non-nil. If the pointer is nil, it is +// 4. A pointer field is marshalled as the underlying type if the pointer is non-nil. If the pointer is nil, it is // marshalled as a BSON null value. // -// 5. When unmarshalling, a field of type interface{} will follow the D/M type mappings listed above. BSON documents +// 5. When unmarshalling, a field of type interface{} will follow the D/M type mappings listed above. BSON documents // unmarshalled into an interface{} field will be unmarshalled as a D. // // The encoding of each struct field can be customized by the "bson" struct tag. @@ -98,13 +100,14 @@ // are not honored, but that can be enabled by creating a StructCodec with JSONFallbackStructTagParser, like below: // // Example: -// structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.JSONFallbackStructTagParser) +// +// structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.JSONFallbackStructTagParser) // // The bson tag gives the name of the field, possibly followed by a comma-separated list of options. // The name may be empty in order to specify options without overriding the default field name. The following options can be used // to configure behavior: // -// 1. omitempty: If the omitempty struct tag is specified on a field, the field will not be marshalled if it is set to +// 1. omitempty: If the omitempty struct tag is specified on a field, the field will not be marshalled if it is set to // the zero value. Fields with language primitive types such as integers, booleans, and strings are considered empty if // their value is equal to the zero value for the type (i.e. 0 for integers, false for booleans, and "" for strings). // Slices, maps, and arrays are considered empty if they are of length zero. Interfaces and pointers are considered @@ -113,16 +116,16 @@ // never considered empty and will be marshalled as embedded documents. // NOTE: It is recommended that this tag be used for all slice and map fields. // -// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of +// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of // the field can fit in a signed int32, the field will be serialized as a BSON int32 rather than a BSON int64. For other // types, this tag is ignored. // -// 3. truncate: If the truncate struct tag is specified on a field with a non-float numeric type, BSON doubles unmarshalled +// 3. truncate: If the truncate struct tag is specified on a field with a non-float numeric type, BSON doubles unmarshalled // into that field will be truncated at the decimal point. For example, if 3.14 is unmarshalled into a field of type int, // it will be unmarshalled as 3. If this tag is not specified, the decoder will throw an error if the value cannot be // decoded without losing precision. For float64 or non-numeric types, this tag is ignored. // -// 4. inline: If the inline struct tag is specified for a struct or map field, the field will be "flattened" when +// 4. inline: If the inline struct tag is specified for a struct or map field, the field will be "flattened" when // marshalling and "un-flattened" when unmarshalling. This means that all of the fields in that struct/map will be // pulled up one level and will become top-level fields rather than being fields in a nested document. For example, if a // map field named "Map" with value map[string]interface{}{"foo": "bar"} is inlined, the resulting document will be @@ -132,7 +135,7 @@ // This tag can be used with fields that are pointers to structs. If an inlined pointer field is nil, it will not be // marshalled. For fields that are not maps or structs, this tag is ignored. // -// Marshalling and Unmarshalling +// # Marshalling and Unmarshalling // // Manually marshalling and unmarshalling can be done with the Marshal and Unmarshal family of functions. package bson diff --git a/bson/mgocompat/doc.go b/bson/mgocompat/doc.go index cb91918d03..43ff5423da 100644 --- a/bson/mgocompat/doc.go +++ b/bson/mgocompat/doc.go @@ -22,37 +22,36 @@ // // The driver uses different types than mgo's bson. The differences are: // -// 1) The driver's bson.RawValue is equivalent to mgo's bson.Raw, but uses Value instead of Data and uses Type, -// which is a bsontype.Type object that wraps a byte, instead of bson.Raw's Kind, a byte. +// 1. The driver's bson.RawValue is equivalent to mgo's bson.Raw, but uses Value instead of Data and uses Type, +// which is a bsontype.Type object that wraps a byte, instead of bson.Raw's Kind, a byte. // -// 2) The driver uses primitive.ObjectID, which is a [12]byte instead of mgo's -// bson.ObjectId, a string. Due to this, the zero value marshals and unmarshals differently -// for Extended JSON, with the driver marshaling as {"ID":"000000000000000000000000"} and -// mgo as {"Id":""}. The driver can unmarshal {"ID":""} to a primitive.ObjectID. +// 2. The driver uses primitive.ObjectID, which is a [12]byte instead of mgo's +// bson.ObjectId, a string. Due to this, the zero value marshals and unmarshals differently +// for Extended JSON, with the driver marshaling as {"ID":"000000000000000000000000"} and +// mgo as {"Id":""}. The driver can unmarshal {"ID":""} to a primitive.ObjectID. // -// 3) The driver's primitive.Symbol is equivalent to mgo's bson.Symbol. +// 3. The driver's primitive.Symbol is equivalent to mgo's bson.Symbol. // -// 4) The driver uses primitive.Timestamp instead of mgo's bson.MongoTimestamp. While -// MongoTimestamp is an int64, primitive.Timestamp stores the time and counter as two separate -// uint32 values, T and I respectively. +// 4. The driver uses primitive.Timestamp instead of mgo's bson.MongoTimestamp. While +// MongoTimestamp is an int64, primitive.Timestamp stores the time and counter as two separate +// uint32 values, T and I respectively. // -// 5) The driver uses primitive.MinKey and primitive.MaxKey, which are struct{}, instead -// of mgo's bson.MinKey and bson.MaxKey, which are int64. +// 5. The driver uses primitive.MinKey and primitive.MaxKey, which are struct{}, instead +// of mgo's bson.MinKey and bson.MaxKey, which are int64. // -// 6) The driver's primitive.Undefined is equivalent to mgo's bson.Undefined. +// 6. The driver's primitive.Undefined is equivalent to mgo's bson.Undefined. // -// 7) The driver's primitive.Binary is equivalent to mgo's bson.Binary, with variables named Subtype -// and Data instead of Kind and Data. +// 7. The driver's primitive.Binary is equivalent to mgo's bson.Binary, with variables named Subtype +// and Data instead of Kind and Data. // -// 8) The driver's primitive.Regex is equivalent to mgo's bson.RegEx. +// 8. The driver's primitive.Regex is equivalent to mgo's bson.RegEx. // -// 9) The driver's primitive.JavaScript is equivalent to mgo's bson.JavaScript with no -// scope and primitive.CodeWithScope is equivalent to mgo's bson.JavaScript with scope. +// 9. The driver's primitive.JavaScript is equivalent to mgo's bson.JavaScript with no +// scope and primitive.CodeWithScope is equivalent to mgo's bson.JavaScript with scope. // -// 10) The driver's primitive.DBPointer is equivalent to mgo's bson.DBPointer, with variables -// named DB and Pointer instead of Namespace and Id. -// -// 11) When implementing the Setter interface, mgocompat.ErrSetZero is equivalent to mgo's -// bson.ErrSetZero. +// 10. The driver's primitive.DBPointer is equivalent to mgo's bson.DBPointer, with variables +// named DB and Pointer instead of Namespace and Id. // +// 11. When implementing the Setter interface, mgocompat.ErrSetZero is equivalent to mgo's +// bson.ErrSetZero. package mgocompat diff --git a/bson/mgocompat/setter_getter.go b/bson/mgocompat/setter_getter.go index 98f22bbb1d..ea54c246e2 100644 --- a/bson/mgocompat/setter_getter.go +++ b/bson/mgocompat/setter_getter.go @@ -29,12 +29,11 @@ import ( // // For example: // -// type MyString string -// -// func (s *MyString) SetBSON(raw bson.RawValue) error { -// return raw.Unmarshal(s) -// } +// type MyString string // +// func (s *MyString) SetBSON(raw bson.RawValue) error { +// return raw.Unmarshal(s) +// } type Setter interface { SetBSON(raw bson.RawValue) error } diff --git a/bson/primitive/decimal.go b/bson/primitive/decimal.go index ffe4eed07a..ba7c9112e9 100644 --- a/bson/primitive/decimal.go +++ b/bson/primitive/decimal.go @@ -191,10 +191,9 @@ func (d Decimal128) IsNaN() bool { // IsInf returns: // -// +1 d == Infinity -// 0 other case -// -1 d == -Infinity -// +// +1 d == Infinity +// 0 other case +// -1 d == -Infinity func (d Decimal128) IsInf() int { if d.h>>58&(1<<5-1) != 0x1E { return 0 diff --git a/bson/primitive/primitive.go b/bson/primitive/primitive.go index b3cba1bf9d..c72ccc1c4d 100644 --- a/bson/primitive/primitive.go +++ b/bson/primitive/primitive.go @@ -182,7 +182,7 @@ type MaxKey struct{} // // Example usage: // -// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} +// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}} type D []E // Map creates a map from the elements of the D. @@ -206,12 +206,12 @@ type E struct { // // Example usage: // -// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} +// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159} type M map[string]interface{} // An A is an ordered representation of a BSON array. // // Example usage: // -// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}} +// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}} type A []interface{} diff --git a/event/doc.go b/event/doc.go index 93b5ede047..da1da4d47f 100644 --- a/event/doc.go +++ b/event/doc.go @@ -14,43 +14,43 @@ // CommandSucceededEvent or CommandFailedEvent through the RequestID field. For // example, the following code collects the names of started events: // -// var commandStarted []string -// cmdMonitor := &event.CommandMonitor{ -// Started: func(_ context.Context, evt *event.CommandStartedEvent) { -// commandStarted = append(commandStarted, evt.CommandName) -// }, -// } -// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// var commandStarted []string +// cmdMonitor := &event.CommandMonitor{ +// Started: func(_ context.Context, evt *event.CommandStartedEvent) { +// commandStarted = append(commandStarted, evt.CommandName) +// }, +// } +// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor) +// client, err := mongo.Connect(context.Background(), clientOpts) // // Monitoring the connection pool requires specifying a PoolMonitor when constructing // a mongo.Client. The following code tracks the number of checked out connections: // -// var int connsCheckedOut -// poolMonitor := &event.PoolMonitor{ -// Event: func(evt *event.PoolEvent) { -// switch evt.Type { -// case event.GetSucceeded: -// connsCheckedOut++ -// case event.ConnectionReturned: -// connsCheckedOut-- -// } -// }, -// } -// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetPoolMonitor(poolMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// var int connsCheckedOut +// poolMonitor := &event.PoolMonitor{ +// Event: func(evt *event.PoolEvent) { +// switch evt.Type { +// case event.GetSucceeded: +// connsCheckedOut++ +// case event.ConnectionReturned: +// connsCheckedOut-- +// } +// }, +// } +// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetPoolMonitor(poolMonitor) +// client, err := mongo.Connect(context.Background(), clientOpts) // // Monitoring server changes specifying a ServerMonitor object when constructing // a mongo.Client. Different functions can be set on the ServerMonitor to // monitor different kinds of events. See ServerMonitor for more details. // The following code appends ServerHeartbeatStartedEvents to a slice: // -// var heartbeatStarted []*event.ServerHeartbeatStartedEvent -// svrMonitor := &event.ServerMonitor{ -// ServerHeartbeatStarted: func(e *event.ServerHeartbeatStartedEvent) { -// heartbeatStarted = append(heartbeatStarted, e) -// } -// } -// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetServerMonitor(svrMonitor) -// client, err := mongo.Connect(context.Background(), clientOpts) +// var heartbeatStarted []*event.ServerHeartbeatStartedEvent +// svrMonitor := &event.ServerMonitor{ +// ServerHeartbeatStarted: func(e *event.ServerHeartbeatStartedEvent) { +// heartbeatStarted = append(heartbeatStarted, e) +// } +// } +// clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetServerMonitor(svrMonitor) +// client, err := mongo.Connect(context.Background(), clientOpts) package event diff --git a/internal/error.go b/internal/error.go index 1fec3f1835..348bcdfb1a 100644 --- a/internal/error.go +++ b/internal/error.go @@ -32,7 +32,7 @@ func RolledUpErrorMessage(err error) string { return err.Error() } -//UnwrapError attempts to unwrap the error down to its root cause. +// UnwrapError attempts to unwrap the error down to its root cause. func UnwrapError(err error) error { switch tErr := err.(type) { diff --git a/mongo/database.go b/mongo/database.go index 57b5417fd3..cd93fb860e 100644 --- a/mongo/database.go +++ b/mongo/database.go @@ -745,7 +745,7 @@ func (db *Database) createCollectionOperation(name string, opts ...*options.Crea // // The viewName parameter specifies the name of the view to create. // -// The viewOn parameter specifies the name of the collection or view on which this view will be created +// # The viewOn parameter specifies the name of the collection or view on which this view will be created // // The pipeline parameter specifies an aggregation pipeline that will be exececuted against the source collection or // view to create this view. diff --git a/mongo/doc.go b/mongo/doc.go index e6e4d9e5f0..5c1a86986e 100644 --- a/mongo/doc.go +++ b/mongo/doc.go @@ -11,67 +11,67 @@ // Basic usage of the driver starts with creating a Client from a connection // string. To do so, call Connect: // -// ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) -// defer cancel() -// client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://foo:bar@localhost:27017")) -// if err != nil { return err } +// ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) +// defer cancel() +// client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://foo:bar@localhost:27017")) +// if err != nil { return err } // // This will create a new client and start monitoring the MongoDB server on localhost. // The Database and Collection types can be used to access the database: // -// collection := client.Database("baz").Collection("qux") +// collection := client.Database("baz").Collection("qux") // // A Collection can be used to query the database or insert documents: // -// res, err := collection.InsertOne(context.Background(), bson.M{"hello": "world"}) -// if err != nil { return err } -// id := res.InsertedID +// res, err := collection.InsertOne(context.Background(), bson.M{"hello": "world"}) +// if err != nil { return err } +// id := res.InsertedID // // Several methods return a cursor, which can be used like this: // -// cur, err := collection.Find(context.Background(), bson.D{}) -// if err != nil { log.Fatal(err) } -// defer cur.Close(context.Background()) -// for cur.Next(context.Background()) { -// // To decode into a struct, use cursor.Decode() -// result := struct{ -// Foo string -// Bar int32 -// }{} -// err := cur.Decode(&result) -// if err != nil { log.Fatal(err) } -// // do something with result... -// -// // To get the raw bson bytes use cursor.Current -// raw := cur.Current -// // do something with raw... -// } -// if err := cur.Err(); err != nil { -// return err -// } +// cur, err := collection.Find(context.Background(), bson.D{}) +// if err != nil { log.Fatal(err) } +// defer cur.Close(context.Background()) +// for cur.Next(context.Background()) { +// // To decode into a struct, use cursor.Decode() +// result := struct{ +// Foo string +// Bar int32 +// }{} +// err := cur.Decode(&result) +// if err != nil { log.Fatal(err) } +// // do something with result... +// +// // To get the raw bson bytes use cursor.Current +// raw := cur.Current +// // do something with raw... +// } +// if err := cur.Err(); err != nil { +// return err +// } // // Cursor.All will decode all of the returned elements at once: // -// var results []struct{ -// Foo string -// Bar int32 -// } -// if err = cur.All(context.Background(), &results); err != nil { -// log.Fatal(err) -// } -// // do something with results... +// var results []struct{ +// Foo string +// Bar int32 +// } +// if err = cur.All(context.Background(), &results); err != nil { +// log.Fatal(err) +// } +// // do something with results... // // Methods that only return a single document will return a *SingleResult, which works // like a *sql.Row: // -// result := struct{ -// Foo string -// Bar int32 -// }{} -// filter := bson.D{{"hello", "world"}} -// err := collection.FindOne(context.Background(), filter).Decode(&result) -// if err != nil { return err } -// // do something with result... +// result := struct{ +// Foo string +// Bar int32 +// }{} +// filter := bson.D{{"hello", "world"}} +// err := collection.FindOne(context.Background(), filter).Decode(&result) +// if err != nil { return err } +// // do something with result... // // All Client, Collection, and Database methods that take parameters of type interface{} // will return ErrNilDocument if nil is passed in for an interface{}. @@ -79,7 +79,7 @@ // Additional examples can be found under the examples directory in the driver's repository and // on the MongoDB website. // -// Error Handling +// # Error Handling // // Errors from the MongoDB server will implement the ServerError interface, which has functions to check for specific // error codes, labels, and message substrings. These can be used to check for and handle specific errors. Some methods, @@ -87,18 +87,19 @@ // functions will return true if any of the contained errors satisfy the check. // // There are also helper functions to check for certain specific types of errors: -// IsDuplicateKeyError(error) -// IsNetworkError(error) -// IsTimeout(error) // -// Potential DNS Issues +// IsDuplicateKeyError(error) +// IsNetworkError(error) +// IsTimeout(error) +// +// # Potential DNS Issues // // Building with Go 1.11+ and using connection strings with the "mongodb+srv"[1] scheme is // incompatible with some DNS servers in the wild due to the change introduced in // https://github.com/golang/go/issues/10622. If you receive an error with the message "cannot // unmarshal DNS message" while running an operation, we suggest you use a different DNS server. // -// Client Side Encryption +// # Client Side Encryption // // Client-side encryption is a new feature in MongoDB 4.2 that allows specific data fields to be encrypted. Using this // feature requires specifying the "cse" build tag during compilation. @@ -131,16 +132,16 @@ // // 3. Windows: // -// mkdir -p c:/libmongocrypt/bin -// mkdir -p c:/libmongocrypt/include +// mkdir -p c:/libmongocrypt/bin +// mkdir -p c:/libmongocrypt/include // -// // Run the curl command in an empty directory as it will create new directories when unpacked. -// curl https://s3.amazonaws.com/mciuploads/libmongocrypt/windows/latest_release/libmongocrypt.tar.gz --output libmongocrypt.tar.gz -// tar -xvzf libmongocrypt.tar.gz +// // Run the curl command in an empty directory as it will create new directories when unpacked. +// curl https://s3.amazonaws.com/mciuploads/libmongocrypt/windows/latest_release/libmongocrypt.tar.gz --output libmongocrypt.tar.gz +// tar -xvzf libmongocrypt.tar.gz // -// cp ./bin/mongocrypt.dll c:/libmongocrypt/bin -// cp ./include/mongocrypt/*.h c:/libmongocrypt/include -// export PATH=$PATH:/cygdrive/c/libmongocrypt/bin +// cp ./bin/mongocrypt.dll c:/libmongocrypt/bin +// cp ./include/mongocrypt/*.h c:/libmongocrypt/include +// export PATH=$PATH:/cygdrive/c/libmongocrypt/bin // // libmongocrypt communicates with the mongocryptd process or mongo_crypt shared library for automatic encryption. // See AutoEncryptionOpts.SetExtraOptions for options to configure use of mongocryptd or mongo_crypt. diff --git a/mongo/errors.go b/mongo/errors.go index 8bd5dd81da..83fe2c5bce 100644 --- a/mongo/errors.go +++ b/mongo/errors.go @@ -631,7 +631,8 @@ const batchErrorsTargetLength = 2000 // to the end. // // Example format: -// "[message 1, message 2, +8 more errors...]" +// +// "[message 1, message 2, +8 more errors...]" func joinBatchErrors(errs []error) string { var buf bytes.Buffer fmt.Fprint(&buf, "[") diff --git a/mongo/gridfs/doc.go b/mongo/gridfs/doc.go index 347c3b9659..69f9d2f1d7 100644 --- a/mongo/gridfs/doc.go +++ b/mongo/gridfs/doc.go @@ -7,29 +7,31 @@ // Package gridfs provides a MongoDB GridFS API. See https://www.mongodb.com/docs/manual/core/gridfs/ for more // information about GridFS and its use cases. // -// Buckets +// # Buckets // // The main type defined in this package is Bucket. A Bucket wraps a mongo.Database instance and operates on two // collections in the database. The first is the files collection, which contains one metadata document per file stored // in the bucket. This collection is named ".files". The second is the chunks collection, which contains // chunks of files. This collection is named ".chunks". // -// Uploading a File +// # Uploading a File // // Files can be uploaded in two ways: -// 1. OpenUploadStream/OpenUploadStreamWithID - These methods return an UploadStream instance. UploadStream -// implements the io.Writer interface and the Write() method can be used to upload a file to the database. // -// 2. UploadFromStream/UploadFromStreamWithID - These methods take an io.Reader, which represents the file to -// upload. They internally create a new UploadStream and close it once the operation is complete. +// 1. OpenUploadStream/OpenUploadStreamWithID - These methods return an UploadStream instance. UploadStream +// implements the io.Writer interface and the Write() method can be used to upload a file to the database. // -// Downloading a File +// 2. UploadFromStream/UploadFromStreamWithID - These methods take an io.Reader, which represents the file to +// upload. They internally create a new UploadStream and close it once the operation is complete. +// +// # Downloading a File // // Similar to uploads, files can be downloaded in two ways: -// 1. OpenDownloadStream/OpenDownloadStreamByName - These methods return a DownloadStream instance. DownloadStream -// implements the io.Reader interface. A file can be read either using the Read() method or any standard library -// methods that reads from an io.Reader such as io.Copy. // -// 2. DownloadToStream/DownloadToStreamByName - These methods take an io.Writer, which represents the download -// destination. They internally create a new DownloadStream and close it once the operation is complete. +// 1. OpenDownloadStream/OpenDownloadStreamByName - These methods return a DownloadStream instance. DownloadStream +// implements the io.Reader interface. A file can be read either using the Read() method or any standard library +// methods that reads from an io.Reader such as io.Copy. +// +// 2. DownloadToStream/DownloadToStreamByName - These methods take an io.Writer, which represents the download +// destination. They internally create a new DownloadStream and close it once the operation is complete. package gridfs diff --git a/mongo/mongo.go b/mongo/mongo.go index 80282527e4..2fa5e54aee 100644 --- a/mongo/mongo.go +++ b/mongo/mongo.go @@ -65,11 +65,10 @@ func (me MarshalError) Error() string { // // Example usage: // -// mongo.Pipeline{ -// {{"$group", bson.D{{"_id", "$state"}, {"totalPop", bson.D{{"$sum", "$pop"}}}}}}, -// {{"$match", bson.D{{"totalPop", bson.D{{"$gte", 10*1000*1000}}}}}}, -// } -// +// mongo.Pipeline{ +// {{"$group", bson.D{{"_id", "$state"}, {"totalPop", bson.D{{"$sum", "$pop"}}}}}}, +// {{"$match", bson.D{{"totalPop", bson.D{{"$gte", 10*1000*1000}}}}}}, +// } type Pipeline []bson.D // transformAndEnsureID is a hack that makes it easy to get a RawValue as the _id value. diff --git a/mongo/options/autoencryptionoptions.go b/mongo/options/autoencryptionoptions.go index 375d899918..cfffc99e3c 100644 --- a/mongo/options/autoencryptionoptions.go +++ b/mongo/options/autoencryptionoptions.go @@ -94,7 +94,7 @@ func (a *AutoEncryptionOptions) SetBypassAutoEncryption(bypass bool) *AutoEncryp // SetExtraOptions specifies a map of options to configure the mongocryptd process or mongo_crypt shared library. // -// Supported Extra Options +// # Supported Extra Options // // "mongocryptdURI" - The mongocryptd URI. Allows setting a custom URI used to communicate with the // mongocryptd process. The default is "mongodb://localhost:27020", which works with the default diff --git a/mongo/options/clientencryptionoptions.go b/mongo/options/clientencryptionoptions.go index b8f6e8710d..8f2695899e 100644 --- a/mongo/options/clientencryptionoptions.go +++ b/mongo/options/clientencryptionoptions.go @@ -56,12 +56,12 @@ func (c *ClientEncryptionOptions) SetTLSConfig(tlsOpts map[string]*tls.Config) * // to the KMS provider. The input map should contain a mapping from each KMS provider to a document containing the necessary // options, as follows: // -// { -// "kmip": { -// "tlsCertificateKeyFile": "foo.pem", -// "tlsCAFile": "fooCA.pem" -// } -// } +// { +// "kmip": { +// "tlsCertificateKeyFile": "foo.pem", +// "tlsCAFile": "fooCA.pem" +// } +// } // // Currently, the following TLS options are supported: // diff --git a/mongo/options/datakeyoptions.go b/mongo/options/datakeyoptions.go index 648d9714e0..059805a6a0 100644 --- a/mongo/options/datakeyoptions.go +++ b/mongo/options/datakeyoptions.go @@ -29,30 +29,36 @@ func DataKey() *DataKeyOptions { // "endpoint" or "keyVaultEndpoint" must be a host name with an optional port number (e.g. "foo.com" or "foo.com:443"). // // When using AWS, the document must have the format: -// { -// region: , -// key: , // The Amazon Resource Name (ARN) to the AWS customer master key (CMK). -// endpoint: Optional // An alternate host identifier to send KMS requests to. -// } +// +// { +// region: , +// key: , // The Amazon Resource Name (ARN) to the AWS customer master key (CMK). +// endpoint: Optional // An alternate host identifier to send KMS requests to. +// } +// // If unset, the "endpoint" defaults to "kms..amazonaws.com". // // When using Azure, the document must have the format: -// { -// keyVaultEndpoint: , // A host identifier to send KMS requests to. -// keyName: , -// keyVersion: Optional // A specific version of the named key. -// } +// +// { +// keyVaultEndpoint: , // A host identifier to send KMS requests to. +// keyName: , +// keyVersion: Optional // A specific version of the named key. +// } +// // If unset, "keyVersion" defaults to the key's primary version. // // When using GCP, the document must have the format: -// { -// projectId: , -// location: , -// keyRing: , -// keyName: , -// keyVersion: Optional, // A specific version of the named key. -// endpoint: Optional // An alternate host identifier to send KMS requests to. -// } +// +// { +// projectId: , +// location: , +// keyRing: , +// keyName: , +// keyVersion: Optional, // A specific version of the named key. +// endpoint: Optional // An alternate host identifier to send KMS requests to. +// } +// // If unset, "keyVersion" defaults to the key's primary version and "endpoint" defaults to "cloudkms.googleapis.com". func (dk *DataKeyOptions) SetMasterKey(masterKey interface{}) *DataKeyOptions { dk.MasterKey = masterKey diff --git a/x/bsonx/bsoncore/document_sequence.go b/x/bsonx/bsoncore/document_sequence.go index 6c858a0109..e35bd0cd9a 100644 --- a/x/bsonx/bsoncore/document_sequence.go +++ b/x/bsonx/bsoncore/document_sequence.go @@ -96,8 +96,8 @@ func (ds *DocumentSequence) Empty() bool { } } -//ResetIterator resets the iteration point for the Next method to the beginning of the document -//sequence. +// ResetIterator resets the iteration point for the Next method to the beginning of the document +// sequence. func (ds *DocumentSequence) ResetIterator() { if ds == nil { return diff --git a/x/mongo/driver/operation/drop_indexes.go b/x/mongo/driver/operation/drop_indexes.go index 5725b04b7c..2e8569021b 100644 --- a/x/mongo/driver/operation/drop_indexes.go +++ b/x/mongo/driver/operation/drop_indexes.go @@ -112,7 +112,6 @@ func (di *DropIndexes) command(dst []byte, desc description.SelectedServer) ([]b } // Index specifies the name of the index to drop. If '*' is specified, all indexes will be dropped. -// func (di *DropIndexes) Index(index string) *DropIndexes { if di == nil { di = new(DropIndexes) diff --git a/x/mongo/driver/operation/find_and_modify.go b/x/mongo/driver/operation/find_and_modify.go index f89f864e42..7c4cb527bf 100644 --- a/x/mongo/driver/operation/find_and_modify.go +++ b/x/mongo/driver/operation/find_and_modify.go @@ -305,7 +305,6 @@ func (fam *FindAndModify) Remove(remove bool) *FindAndModify { } // Sort determines which document the operation modifies if the query matches multiple documents.The first document matched by the sort order will be modified. -// func (fam *FindAndModify) Sort(sort bsoncore.Document) *FindAndModify { if fam == nil { fam = new(FindAndModify)