Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pip-services3-go/pip-services3-mo…
Browse files Browse the repository at this point in the history
…ngodb-go
  • Loading branch information
levichevdmitry committed Apr 5, 2021
2 parents ff6712b + 45a1a5a commit fa5141e
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 5,537 deletions.
10 changes: 4 additions & 6 deletions CHNAGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> MongoDB components for Golang Changelog

## <a name="1.1.0"></a> 1.1.0 (2021-04-05)
## <a name="1.1.0"></a> 1.1.0 (2021-04-03)

### Features
* Update dependencies
* Moved to go 1.16
* Moved connection to connect package, introduced overrides
* Added DefineSchema method
### Breaking changes
* Moved MongoDbConnection to connect package
* Added IMongoDbPersistenceOverrides to persistence constructors to support virtual methods

## <a name="1.0.5"></a> 1.0.5 (2020-12-11)

Expand Down
15 changes: 7 additions & 8 deletions build/DefaultMongoDbFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ package build
import (
cref "github.com/pip-services3-go/pip-services3-commons-go/refer"
cbuild "github.com/pip-services3-go/pip-services3-components-go/build"
cmngpersist "github.com/pip-services3-go/pip-services3-mongodb-go/persistence"
conn "github.com/pip-services3-go/pip-services3-mongodb-go/connect"
)

//DefaultMongoDbFactory helps creates MongoDb components by their descriptors.
//See Factory
//See MongoDbConnection
type DefaultMongoDbFactory struct {
cbuild.Factory
Descriptor *cref.Descriptor
MongoDbConnectionDescriptor *cref.Descriptor
}

// NewDefaultMongoDbFactory are create a new instance of the factory.
// Return *DefaultMongoDbFactory
func NewDefaultMongoDbFactory() *DefaultMongoDbFactory {
mongoDBFactory := DefaultMongoDbFactory{}
mongoDBFactory.Descriptor = cref.NewDescriptor("pip-services", "factory", "rpc", "default", "1.0")
mongoDBFactory.MongoDbConnectionDescriptor = cref.NewDescriptor("pip-services", "connection", "mongodb", "*", "1.0")
mongoDBFactory.RegisterType(mongoDBFactory.MongoDbConnectionDescriptor, cmngpersist.NewMongoDbConnection)
return &mongoDBFactory
c := DefaultMongoDbFactory{}

mongoDbConnectionDescriptor := cref.NewDescriptor("pip-services", "connection", "mongodb", "*", "1.0")

c.RegisterType(mongoDbConnectionDescriptor, persist.NewMongoDbConnection)
return &c
}
34 changes: 15 additions & 19 deletions persistence/MongoDbConnection.go → connect/MongoDbConnection.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package persistence
package connect

import (
"context"
Expand All @@ -8,7 +8,6 @@ import (
cerror "github.com/pip-services3-go/pip-services3-commons-go/errors"
crefer "github.com/pip-services3-go/pip-services3-commons-go/refer"
clog "github.com/pip-services3-go/pip-services3-components-go/log"
mcon "github.com/pip-services3-go/pip-services3-mongodb-go/connect"
mongodrv "go.mongodb.org/mongo-driver/mongo"
mongoclopt "go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
Expand Down Expand Up @@ -57,7 +56,7 @@ type MongoDbConnection struct {
// The logger.
Logger *clog.CompositeLogger
// The connection resolver.
ConnectionResolver *mcon.MongoDbConnectionResolver
ConnectionResolver *MongoDbConnectionResolver
// The configuration options.
Options *cconf.ConfigParams
// The MongoDB connection object.
Expand All @@ -70,8 +69,8 @@ type MongoDbConnection struct {

// NewMongoDbConnection are creates a new instance of the connection component.
// Returns *MongoDbConnection with default config
func NewMongoDbConnection() (c *MongoDbConnection) {
mc := MongoDbConnection{
func NewMongoDbConnection() *MongoDbConnection {
c := MongoDbConnection{
defaultConfig: cconf.NewConfigParamsFromTuples(
"options.max_pool_size", "2",
"options.keep_alive", "0",
Expand All @@ -81,11 +80,11 @@ func NewMongoDbConnection() (c *MongoDbConnection) {
//The logger.
Logger: clog.NewCompositeLogger(),
//The connection resolver.
ConnectionResolver: mcon.NewMongoDbConnectionResolver(),
ConnectionResolver: NewMongoDbConnectionResolver(),
// The configuration options.
Options: cconf.NewEmptyConfigParams(),
}
return &mc
return &c
}

// Configure is configures component by passing configuration parameters.
Expand Down Expand Up @@ -114,17 +113,13 @@ func (c *MongoDbConnection) IsOpen() bool {
}

func (c *MongoDbConnection) composeSettings(settings *mongoclopt.ClientOptions) {
var maxPoolSize uint64
maxPoolSize = (uint64)(c.Options.GetAsInteger("max_pool_size"))
var MaxConnIdleTime time.Duration
maxPoolSize := (uint64)(c.Options.GetAsInteger("max_pool_size"))
keepAlive := c.Options.GetAsInteger("keep_alive")
MaxConnIdleTime = (time.Duration)(keepAlive) * time.Millisecond
var ConnectTimeout time.Duration
MaxConnIdleTime := (time.Duration)(keepAlive) * time.Millisecond
connectTimeoutMS := c.Options.GetAsInteger("connect_timeout")
ConnectTimeout = (time.Duration)(connectTimeoutMS) * time.Millisecond
var SocketTimeout time.Duration
ConnectTimeout := (time.Duration)(connectTimeoutMS) * time.Millisecond
socketTimeoutMS := c.Options.GetAsInteger("socket_timeout")
SocketTimeout = (time.Duration)(socketTimeoutMS) * time.Millisecond
SocketTimeout := (time.Duration)(socketTimeoutMS) * time.Millisecond

replicaSet := c.Options.GetAsNullableString("replica_set")
authSource := c.Options.GetAsString("auth_source")
Expand All @@ -148,10 +143,11 @@ func (c *MongoDbConnection) composeSettings(settings *mongoclopt.ClientOptions)

// Auth params
if authSource != "" && authUser != "" && authPassword != "" {
var authParams mongoclopt.Credential
authParams.AuthSource = authSource
authParams.Username = authUser
authParams.Password = authPassword
authParams := mongoclopt.Credential{
AuthSource: authSource,
Username: authUser,
Password: authPassword,
}
settings.SetAuth(authParams)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13
FROM golang:1.16

# Set environment variables for Go
ENV GO111MODULE=on \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.docgen
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13
FROM golang:1.16

# Set environment variables for Go
ENV GO111MODULE=on
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13
FROM golang:1.16

# Set environment variables for Go
ENV GO111MODULE=on \
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.3'

services:
mongo:
image: mongo:latest
ports:
- "27017:27017"

Loading

0 comments on commit fa5141e

Please sign in to comment.