blob: ac10518841b466d94776e891a2e2c5a6bf1334e4 [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// 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
7package session
8
9import (
10 "github.com/mongodb/mongo-go-driver/mongo/readconcern"
11 "github.com/mongodb/mongo-go-driver/mongo/readpref"
12 "github.com/mongodb/mongo-go-driver/mongo/writeconcern"
13)
14
15// ClientOptions represents all possible options for creating a client session.
16type ClientOptions struct {
17 CausalConsistency *bool
18 DefaultReadConcern *readconcern.ReadConcern
19 DefaultWriteConcern *writeconcern.WriteConcern
20 DefaultReadPreference *readpref.ReadPref
21}
22
23// TransactionOptions represents all possible options for starting a transaction in a session.
24type TransactionOptions struct {
25 ReadConcern *readconcern.ReadConcern
26 WriteConcern *writeconcern.WriteConcern
27 ReadPreference *readpref.ReadPref
28}
29
30func mergeClientOptions(opts ...*ClientOptions) *ClientOptions {
31 c := &ClientOptions{}
32 for _, opt := range opts {
33 if opt == nil {
34 continue
35 }
36 if opt.CausalConsistency != nil {
37 c.CausalConsistency = opt.CausalConsistency
38 }
39 if opt.DefaultReadConcern != nil {
40 c.DefaultReadConcern = opt.DefaultReadConcern
41 }
42 if opt.DefaultReadPreference != nil {
43 c.DefaultReadPreference = opt.DefaultReadPreference
44 }
45 if opt.DefaultWriteConcern != nil {
46 c.DefaultWriteConcern = opt.DefaultWriteConcern
47 }
48 }
49
50 return c
51}