...

Source file src/go.mongodb.org/mongo-driver/x/mongo/driver/session/options.go

Documentation: go.mongodb.org/mongo-driver/x/mongo/driver/session

     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 session
     8  
     9  import (
    10  	"time"
    11  
    12  	"go.mongodb.org/mongo-driver/mongo/readconcern"
    13  	"go.mongodb.org/mongo-driver/mongo/readpref"
    14  	"go.mongodb.org/mongo-driver/mongo/writeconcern"
    15  )
    16  
    17  // ClientOptions represents all possible options for creating a client session.
    18  type ClientOptions struct {
    19  	CausalConsistency     *bool
    20  	DefaultReadConcern    *readconcern.ReadConcern
    21  	DefaultWriteConcern   *writeconcern.WriteConcern
    22  	DefaultReadPreference *readpref.ReadPref
    23  	DefaultMaxCommitTime  *time.Duration
    24  	Snapshot              *bool
    25  }
    26  
    27  // TransactionOptions represents all possible options for starting a transaction in a session.
    28  type TransactionOptions struct {
    29  	ReadConcern    *readconcern.ReadConcern
    30  	WriteConcern   *writeconcern.WriteConcern
    31  	ReadPreference *readpref.ReadPref
    32  	MaxCommitTime  *time.Duration
    33  }
    34  
    35  func mergeClientOptions(opts ...*ClientOptions) *ClientOptions {
    36  	c := &ClientOptions{}
    37  	for _, opt := range opts {
    38  		if opt == nil {
    39  			continue
    40  		}
    41  		if opt.CausalConsistency != nil {
    42  			c.CausalConsistency = opt.CausalConsistency
    43  		}
    44  		if opt.DefaultReadConcern != nil {
    45  			c.DefaultReadConcern = opt.DefaultReadConcern
    46  		}
    47  		if opt.DefaultReadPreference != nil {
    48  			c.DefaultReadPreference = opt.DefaultReadPreference
    49  		}
    50  		if opt.DefaultWriteConcern != nil {
    51  			c.DefaultWriteConcern = opt.DefaultWriteConcern
    52  		}
    53  		if opt.DefaultMaxCommitTime != nil {
    54  			c.DefaultMaxCommitTime = opt.DefaultMaxCommitTime
    55  		}
    56  		if opt.Snapshot != nil {
    57  			c.Snapshot = opt.Snapshot
    58  		}
    59  	}
    60  
    61  	return c
    62  }
    63  

View as plain text