Documentation ¶
Index ¶
- func Bind(r io.Reader, v interface{}) error
- func Connect(ctx context.Context, opts *options.ClientOptions, u string, extras ...string) (*driver.Client, map[string]interface{}, error)
- func MakeTestConnection(t *testing.T) (mg *driver.Client, coll *driver.Collection, teardown func())
- func MakeTestConnectionWithColl(t *testing.T, cname string) (mg *driver.Client, coll *driver.Collection, teardown func())
- func PrepIndex(keys ...string) driver.IndexModel
- func PrepSort(sort ...string) bson.D
- func SecretsMongoUrls(urls ...string) (res []string)
- type BufferedWriter
- type BufferedWriterMongo
- func (bw *BufferedWriterMongo) Close() (err error)
- func (bw *BufferedWriterMongo) Flush() error
- func (bw *BufferedWriterMongo) WithAutoFlush(duration time.Duration) *BufferedWriterMongo
- func (bw *BufferedWriterMongo) WithCollection(collection string) *BufferedWriterMongo
- func (bw *BufferedWriterMongo) Write(rec interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
func Connect(ctx context.Context, opts *options.ClientOptions, u string, extras ...string) (*driver.Client, map[string]interface{}, error)
Connect to mongo url and return client. Supports expanded url params to pass a set of custom values in the url
func MakeTestConnection ¶
MakeTestConnection connects to MONGO_TEST url or "mongo" host (in no env) and returns new connection. collection name randomized on each call
func MakeTestConnectionWithColl ¶ added in v2.1.0
func MakeTestConnectionWithColl(t *testing.T, cname string) (mg *driver.Client, coll *driver.Collection, teardown func())
MakeTestConnectionWithColl connects to MONGO_TEST url or "mongo" host (in no env) and returns new connection. collection name passed in as cname param
func PrepIndex ¶ added in v2.1.0
func PrepIndex(keys ...string) driver.IndexModel
PrepIndex prepares index params for mongo driver and returns IndexModel
func PrepSort ¶ added in v2.1.0
PrepSort prepares sort params for mongo driver and returns bson.D Input string provided as [+|-]field1,[+|-]field2,[+|-]field3... + means ascending, - means descending. Lack of + or - in the beginning of the field name means ascending sort.
func SecretsMongoUrls ¶ added in v2.2.0
SecretsMongoUrls retrieves passwords from mongo urls. this is needed to pass mongo password to the logging masking function
Types ¶
type BufferedWriter ¶
BufferedWriter defines interface for writes and flush
type BufferedWriterMongo ¶
type BufferedWriterMongo struct {
// contains filtered or unexported fields
}
BufferedWriterMongo collects records in local buffer and flushes them as filled. Thread safe by default using both DB and collection from provided connection. Collection can be customized by WithCollection method. Optional flush duration to save on interval
func NewBufferedWriter ¶
func NewBufferedWriter(client *driver.Client, db, collection string, size int) *BufferedWriterMongo
NewBufferedWriter makes batch writer for given size and connection
func (*BufferedWriterMongo) Close ¶
func (bw *BufferedWriterMongo) Close() (err error)
Close flushes all in-fly records and terminates background auto-flusher
func (*BufferedWriterMongo) Flush ¶
func (bw *BufferedWriterMongo) Flush() error
Flush writes everything left in buffer to mongo
func (*BufferedWriterMongo) WithAutoFlush ¶
func (bw *BufferedWriterMongo) WithAutoFlush(duration time.Duration) *BufferedWriterMongo
WithAutoFlush sets auto flush duration
func (*BufferedWriterMongo) WithCollection ¶
func (bw *BufferedWriterMongo) WithCollection(collection string) *BufferedWriterMongo
WithCollection sets custom collection to use with writer
func (*BufferedWriterMongo) Write ¶
func (bw *BufferedWriterMongo) Write(rec interface{}) error
Write to buffer and, as filled, to mongo. If flushDuration defined check for automatic flush