https://github.com/danteay/gomongo
A MongoDB conection pool based on Circuitbreaker
https://github.com/danteay/gomongo
Last synced: about 1 month ago
JSON representation
A MongoDB conection pool based on Circuitbreaker
- Host: GitHub
- URL: https://github.com/danteay/gomongo
- Owner: danteay
- License: apache-2.0
- Created: 2018-06-29T18:18:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-29T19:11:08.000Z (almost 7 years ago)
- Last Synced: 2025-01-28T22:31:27.426Z (3 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gomongo
## Install
```bash
go get -u -v github.com/danteay/gomongo
```And import in your files whit the next lines:
```go
import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"github.com/danteay/gomongo"
)
```## Configure
Setup config for circut and recover strategies
```go
conf := gomongo.MongoOptions{
Host: "MONGO_HOST",
User: "MONGO_USER",
Pass: "MONGO_PASS",
Dbas: "MONGO_DBAS",
Poolsize: 10,
FailRate: 0.25,
Universe: 4,
TimeOut: time.Second * 1,
}
```Init connection pool
```go
pool, err := gomongo.InitPool(conf)if err != nil {
fmt.Println(err)
}
```Execute querys inside of the circuit breaker
```go
type Person struct {
Name string
Phone string
}errQuery := pool.Execute(func(db *mgo.Database) error {
return db.C("people").Insert(
&Person{"Ale", "+55 53 8116 9639"},
&Person{"Cla", "+55 53 8402 8510"},
)
})if errQuery != nil {
fmt.Println(errQuery)
}
```Helt check of the pool connection
```go
fmt.Println("==>> State: ", pool.State())
```