|
I'm using JetBrains Goland IDE with next simple code to connection ping
// code placeholder
|
ctx, cancel := context.WithTimeout(context.Background(), appConfig.DB.Timeout*time.Second)
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(appConfig.DB.URI))
|
defer cancel()
|
//Call the connect function of client
|
//noinspection GoNilness
|
err = client.Ping(ctx, readpref.Primary())
|
if err != nil {
|
logrus.WithField("mongo", appConfig.DB.URI).Fatal("Mongo connection failed after timeout")
|
} else {
|
logrus.WithField("mongo", appConfig.DB.URI).Info("Mongo connected")
|
appConfig.DB.Client = client
|
}
|
method err = client.Ping(ctx, readpref.Primary()) show an error with message:

Can I fix myself in my code or it's deeper?
|