migration to replicaset connection
Some checks failed
ci/woodpecker/push/ledger Pipeline is pending
ci/woodpecker/push/nats Pipeline is pending
ci/woodpecker/push/notification Pipeline is pending
ci/woodpecker/push/payments_orchestrator Pipeline is pending
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline failed
ci/woodpecker/push/bump_version unknown status
ci/woodpecker/push/frontend Pipeline failed
Some checks failed
ci/woodpecker/push/ledger Pipeline is pending
ci/woodpecker/push/nats Pipeline is pending
ci/woodpecker/push/notification Pipeline is pending
ci/woodpecker/push/payments_orchestrator Pipeline is pending
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline failed
ci/woodpecker/push/bump_version unknown status
ci/woodpecker/push/frontend Pipeline failed
This commit is contained in:
@@ -1,22 +1,49 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func buildURI(s *DBSettings) string {
|
||||
u := &url.URL{
|
||||
Scheme: "mongodb",
|
||||
Host: s.Host,
|
||||
Path: "/" + url.PathEscape(s.Database), // /my%20db
|
||||
func buildOptions(s *DBSettings) *options.ClientOptions {
|
||||
opts := options.Client()
|
||||
|
||||
if s.URI != "" {
|
||||
return opts.ApplyURI(s.URI)
|
||||
}
|
||||
|
||||
hosts := make([]string, 0, len(s.Hosts)+1)
|
||||
for _, h := range s.Hosts {
|
||||
if trimmed := strings.TrimSpace(h); trimmed != "" {
|
||||
hosts = append(hosts, trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
if len(hosts) == 0 && s.Host != "" {
|
||||
host := s.Host
|
||||
if _, _, err := net.SplitHostPort(host); err != nil && s.Port != "" {
|
||||
host = net.JoinHostPort(host, s.Port)
|
||||
}
|
||||
hosts = append(hosts, host)
|
||||
}
|
||||
|
||||
if len(hosts) > 0 {
|
||||
opts.SetHosts(hosts)
|
||||
}
|
||||
|
||||
q := url.Values{}
|
||||
if s.ReplicaSet != "" {
|
||||
q.Set("replicaSet", s.ReplicaSet)
|
||||
opts.SetReplicaSet(s.ReplicaSet)
|
||||
}
|
||||
|
||||
u.RawQuery = q.Encode()
|
||||
cred := options.Credential{
|
||||
AuthMechanism: s.AuthMechanism,
|
||||
AuthSource: s.AuthSource,
|
||||
Username: s.User,
|
||||
Password: s.Password,
|
||||
}
|
||||
opts.SetAuth(cred)
|
||||
|
||||
return u.String()
|
||||
return opts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user