...

Source file src/go.mongodb.org/mongo-driver/mongo/integration/unified/server_api_options.go

Documentation: go.mongodb.org/mongo-driver/mongo/integration/unified

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     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  // serverAPIOptions is a wrapper for *options.ServerAPIOptions. This type implements the bson.Unmarshaler interface
    17  // to convert BSON documents to a serverAPIOptions instance.
    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