...
1
2
3
4
5
6
7 package unified
8
9 import (
10 "fmt"
11
12 "go.mongodb.org/mongo-driver/bson"
13 "go.mongodb.org/mongo-driver/mongo/options"
14 )
15
16
17
18 type serverAPIOptions struct {
19 *options.ServerAPIOptions
20 }
21
22 type serverAPIVersion = options.ServerAPIVersion
23
24 var _ bson.Unmarshaler = (*serverAPIOptions)(nil)
25
26 func (s *serverAPIOptions) UnmarshalBSON(data []byte) error {
27 var temp struct {
28 ServerAPIVersion serverAPIVersion `bson:"version"`
29 DeprecationErrors *bool `bson:"deprecationErrors"`
30 Strict *bool `bson:"strict"`
31 Extra map[string]interface{} `bson:",inline"`
32 }
33 if err := bson.Unmarshal(data, &temp); err != nil {
34 return fmt.Errorf("error unmarshalling to temporary serverAPIOptions object: %v", err)
35 }
36 if len(temp.Extra) > 0 {
37 return fmt.Errorf("unrecognized fields for serverAPIOptions: %v", mapKeys(temp.Extra))
38 }
39
40 s.ServerAPIOptions = options.ServerAPI(temp.ServerAPIVersion)
41 if temp.DeprecationErrors != nil {
42 s.SetDeprecationErrors(*temp.DeprecationErrors)
43 }
44 if temp.Strict != nil {
45 s.SetStrict(*temp.Strict)
46 }
47
48 return nil
49 }
50
View as plain text