github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/serverapioptions.go (about) 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 options 8 9 import ( 10 "fmt" 11 ) 12 13 // ServerAPIOptions represents options used to configure the API version sent to the server 14 // when running commands. 15 // 16 // Sending a specified server API version causes the server to behave in a manner compatible with that 17 // API version. It also causes the driver to behave in a manner compatible with the driver’s behavior as 18 // of the release when the driver first started to support the specified server API version. 19 // 20 // The user must specify a ServerAPIVersion if including ServerAPIOptions in their client. That version 21 // must also be currently supported by the driver. This version of the driver supports API version "1". 22 type ServerAPIOptions struct { 23 ServerAPIVersion ServerAPIVersion 24 Strict *bool 25 DeprecationErrors *bool 26 } 27 28 // ServerAPI creates a new ServerAPIOptions configured with the provided serverAPIversion. 29 func ServerAPI(serverAPIVersion ServerAPIVersion) *ServerAPIOptions { 30 return &ServerAPIOptions{ServerAPIVersion: serverAPIVersion} 31 } 32 33 // SetStrict specifies whether the server should return errors for features that are not part of the API version. 34 func (s *ServerAPIOptions) SetStrict(strict bool) *ServerAPIOptions { 35 s.Strict = &strict 36 return s 37 } 38 39 // SetDeprecationErrors specifies whether the server should return errors for deprecated features. 40 func (s *ServerAPIOptions) SetDeprecationErrors(deprecationErrors bool) *ServerAPIOptions { 41 s.DeprecationErrors = &deprecationErrors 42 return s 43 } 44 45 // ServerAPIVersion represents an API version that can be used in ServerAPIOptions. 46 type ServerAPIVersion string 47 48 const ( 49 // ServerAPIVersion1 is the first API version. 50 ServerAPIVersion1 ServerAPIVersion = "1" 51 ) 52 53 // Validate determines if the provided ServerAPIVersion is currently supported by the driver. 54 func (sav ServerAPIVersion) Validate() error { 55 switch sav { 56 case ServerAPIVersion1: 57 return nil 58 } 59 return fmt.Errorf("api version %q not supported; this driver version only supports API version \"1\"", sav) 60 }