diff options
| author | Jacky Zhao <[email protected]> | 2023-07-09 14:24:53 -0700 |
|---|---|---|
| committer | Jacky Zhao <[email protected]> | 2023-07-09 14:24:53 -0700 |
| commit | 61da551a9262e17501c1c96c36255f6fa0cd1b84 (patch) | |
| tree | 46253c8b9cd9005a3faf5565038c6895af592fa1 | |
| parent | more connection checks (diff) | |
| download | ctrl-v-61da551a9262e17501c1c96c36255f6fa0cd1b84.tar.xz ctrl-v-61da551a9262e17501c1c96c36255f6fa0cd1b84.zip | |
add tls config
| -rw-r--r-- | backend/db/mongo.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/backend/db/mongo.go b/backend/db/mongo.go index bc0f343..dc1dd25 100644 --- a/backend/db/mongo.go +++ b/backend/db/mongo.go @@ -2,14 +2,15 @@ package db import ( "context" + "crypto/tls" "fmt" "time" log "github.com/sirupsen/logrus" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/readpref" "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readpref" ) var Session *mongo.Session @@ -22,9 +23,9 @@ func initSessions(user, pass, ip string) { URIfmt := "mongodb://%s:%s@%s:27017" mongoURI := fmt.Sprintf(URIfmt, user, pass, ip) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoURI)) + client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoURI).SetTLSConfig(&tls.Config{})) if err != nil { log.Fatalf("error establishing connection to mongo: %s", err.Error()) } |