Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Oct 2, 2023
1 parent 23df976 commit e261dc3
Showing 1 changed file with 135 additions and 1 deletion.
136 changes: 135 additions & 1 deletion mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Connect(ctx context.Context, opts ...*options.ClientOptions) (*Client, erro
// set in the Auth field for the first option, and Password is set for the second but with no
// Username, after the merge the Username field will be empty.
func newClient(opts ...*options.ClientOptions) (*Client, error) {
clientOpt := options.MergeClientOptions(opts...)
clientOpt := mergeClientOptions(opts...)

id, err := uuid.New()
if err != nil {
Expand Down Expand Up @@ -501,6 +501,140 @@ func (c *Client) configureAutoEncryption(clientOpts *options.ClientOptions) erro
return nil
}

func mergeClientOptions(opts ...*options.ClientOptions) *options.ClientOptions {
c := options.Client()

for _, opt := range opts {
if opt == nil {
continue
}

if opt.Dialer != nil {
c.Dialer = opt.Dialer
}
if opt.AppName != nil {
c.AppName = opt.AppName
}
if opt.Auth != nil {
c.Auth = opt.Auth
}
if opt.Compressors != nil {
c.Compressors = opt.Compressors
}
if opt.ConnectTimeout != nil {
c.ConnectTimeout = opt.ConnectTimeout
}
if opt.Crypt != nil {
c.Crypt = opt.Crypt
}
if opt.HeartbeatInterval != nil {
c.HeartbeatInterval = opt.HeartbeatInterval
}
if len(opt.Hosts) > 0 {
c.Hosts = opt.Hosts
}
if opt.HTTPClient != nil {
c.HTTPClient = opt.HTTPClient
}
if opt.LoadBalanced != nil {
c.LoadBalanced = opt.LoadBalanced
}
if opt.LocalThreshold != nil {
c.LocalThreshold = opt.LocalThreshold
}
if opt.MaxConnIdleTime != nil {
c.MaxConnIdleTime = opt.MaxConnIdleTime
}
if opt.MaxPoolSize != nil {
c.MaxPoolSize = opt.MaxPoolSize
}
if opt.MinPoolSize != nil {
c.MinPoolSize = opt.MinPoolSize
}
if opt.MaxConnecting != nil {
c.MaxConnecting = opt.MaxConnecting
}
if opt.PoolMonitor != nil {
c.PoolMonitor = opt.PoolMonitor
}
if opt.Monitor != nil {
c.Monitor = opt.Monitor
}
if opt.ServerAPIOptions != nil {
c.ServerAPIOptions = opt.ServerAPIOptions
}
if opt.ServerMonitor != nil {
c.ServerMonitor = opt.ServerMonitor
}
if opt.ReadConcern != nil {
c.ReadConcern = opt.ReadConcern
}
if opt.ReadPreference != nil {
c.ReadPreference = opt.ReadPreference
}
if opt.BSONOptions != nil {
c.BSONOptions = opt.BSONOptions
}
if opt.Registry != nil {
c.Registry = opt.Registry
}
if opt.ReplicaSet != nil {
c.ReplicaSet = opt.ReplicaSet
}
if opt.RetryWrites != nil {
c.RetryWrites = opt.RetryWrites
}
if opt.RetryReads != nil {
c.RetryReads = opt.RetryReads
}
if opt.ServerSelectionTimeout != nil {
c.ServerSelectionTimeout = opt.ServerSelectionTimeout
}
if opt.Direct != nil {
c.Direct = opt.Direct
}
if opt.SocketTimeout != nil {
c.SocketTimeout = opt.SocketTimeout
}
if opt.SRVMaxHosts != nil {
c.SRVMaxHosts = opt.SRVMaxHosts
}
if opt.SRVServiceName != nil {
c.SRVServiceName = opt.SRVServiceName
}
if opt.Timeout != nil {
c.Timeout = opt.Timeout
}
if opt.TLSConfig != nil {
c.TLSConfig = opt.TLSConfig
}
if opt.WriteConcern != nil {
c.WriteConcern = opt.WriteConcern
}
if opt.ZlibLevel != nil {
c.ZlibLevel = opt.ZlibLevel
}
if opt.ZstdLevel != nil {
c.ZstdLevel = opt.ZstdLevel
}
if opt.AutoEncryptionOptions != nil {
c.AutoEncryptionOptions = opt.AutoEncryptionOptions
}
if opt.Deployment != nil {
c.Deployment = opt.Deployment
}
if opt.DisableOCSPEndpointCheck != nil {
c.DisableOCSPEndpointCheck = opt.DisableOCSPEndpointCheck
}
if opt.LoggerOptions != nil {
c.LoggerOptions = opt.LoggerOptions
}
c.ApplyURI(opt.GetURI())
}

return c
}

func (c *Client) getOrCreateInternalClient(clientOpts *options.ClientOptions) (*Client, error) {
if c.internalClientFLE != nil {
return c.internalClientFLE, nil
Expand Down

0 comments on commit e261dc3

Please sign in to comment.