mongo

package module
v0.0.0-...-f331fff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mongo is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*mongo.Database
	// contains filtered or unexported fields
}

func New

func New(c Config) *Client

New initializes MongoDB driver with the provided configuration. The Connect method must be called to establish a connection to MongoDB. Usage: client := New(config) client.UseLogger(loggerInstance) client.UseMetrics(metricsInstance) client.Connect()

func (*Client) Connect

func (c *Client) Connect()

Connect establishes a connection to MongoDB and registers metrics using the provided configuration when the client was Created.

func (*Client) CountDocuments

func (c *Client) CountDocuments(ctx context.Context, collection string, filter interface{}) (int64, error)

CountDocuments counts the number of documents in the specified collection based on the provided filter.

func (*Client) DeleteMany

func (c *Client) DeleteMany(ctx context.Context, collection string, filter interface{}) (int64, error)

DeleteMany deletes multiple documents from the specified collection based on the provided filter.

func (*Client) DeleteOne

func (c *Client) DeleteOne(ctx context.Context, collection string, filter interface{}) (int64, error)

DeleteOne deletes a single document from the specified collection based on the provided filter.

func (*Client) Drop

func (c *Client) Drop(ctx context.Context, collection string) error

Drop drops the specified collection from the database.

func (*Client) Find

func (c *Client) Find(ctx context.Context, collection string, filter, results interface{}) error

Find retrieves documents from the specified collection based on the provided filter and binds response to result.

func (*Client) FindOne

func (c *Client) FindOne(ctx context.Context, collection string, filter, result interface{}) error

FindOne retrieves a single document from the specified collection based on the provided filter and binds response to result.

func (*Client) HealthCheck

func (c *Client) HealthCheck() interface{}

HealthCheck checks the health of the MongoDB client by pinging the database.

func (*Client) InsertMany

func (c *Client) InsertMany(ctx context.Context, collection string, documents []interface{}) ([]interface{}, error)

InsertMany inserts multiple documents into the specified collection.

func (*Client) InsertOne

func (c *Client) InsertOne(ctx context.Context, collection string, document interface{}) (interface{}, error)

InsertOne inserts a single document into the specified collection.

func (*Client) UpdateByID

func (c *Client) UpdateByID(ctx context.Context, collection string, id, update interface{}) (int64, error)

UpdateByID updates a document in the specified collection by its ID.

func (*Client) UpdateMany

func (c *Client) UpdateMany(ctx context.Context, collection string, filter, update interface{}) (int64, error)

UpdateMany updates multiple documents in the specified collection based on the provided filter.

func (*Client) UpdateOne

func (c *Client) UpdateOne(ctx context.Context, collection string, filter, update interface{}) error

UpdateOne updates a single document in the specified collection based on the provided filter.

func (*Client) UseLogger

func (c *Client) UseLogger(logger interface{})

UseLogger sets the logger for the MongoDB client which asserts the Logger interface.

func (*Client) UseMetrics

func (c *Client) UseMetrics(metrics interface{})

UseMetrics sets the metrics for the MongoDB client which asserts the Metrics interface.

type Config

type Config struct {
	URI      string
	Database string
}

type Health

type Health struct {
	Status  string                 `json:"status,omitempty"`
	Details map[string]interface{} `json:"details,omitempty"`
}

type Level

type Level int

Level represents different logging levels.

const (
	DEBUG Level = iota + 1
	INFO
	ERROR
)

type Logger

type Logger interface {
	Debugf(pattern string, args ...interface{})
	Logf(pattern string, args ...interface{})
	Errorf(patter string, args ...interface{})
}

func NewMockLogger

func NewMockLogger(level Level) Logger

type Metrics

type Metrics interface {
	NewHistogram(name, desc string, buckets ...float64)

	RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
}

type MockLogger

type MockLogger struct {
	// contains filtered or unexported fields
}

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(pattern string, args ...interface{})

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(patter string, args ...interface{})

func (*MockLogger) Logf

func (m *MockLogger) Logf(pattern string, args ...interface{})

type MockMetrics

type MockMetrics struct {
	// contains filtered or unexported fields
}

MockMetrics is a mock of Metrics interface.

func NewMockMetrics

func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics

NewMockMetrics creates a new mock instance.

func (*MockMetrics) EXPECT

func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMetrics) NewHistogram

func (m *MockMetrics) NewHistogram(name, desc string, buckets ...float64)

NewHistogram mocks base method.

func (*MockMetrics) RecordHistogram

func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)

RecordHistogram mocks base method.

type MockMetricsMockRecorder

type MockMetricsMockRecorder struct {
	// contains filtered or unexported fields
}

MockMetricsMockRecorder is the mock recorder for MockMetrics.

func (*MockMetricsMockRecorder) NewHistogram

func (mr *MockMetricsMockRecorder) NewHistogram(name, desc any, buckets ...any) *gomock.Call

NewHistogram indicates an expected call of NewHistogram.

func (*MockMetricsMockRecorder) RecordHistogram

func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call

RecordHistogram indicates an expected call of RecordHistogram.

type QueryLog

type QueryLog struct {
	Query      string      `json:"query"`
	Duration   int64       `json:"duration"`
	Collection string      `json:"collection,omitempty"`
	Filter     interface{} `json:"filter,omitempty"`
	ID         interface{} `json:"id,omitempty"`
	Update     interface{} `json:"update,omitempty"`
}

func (*QueryLog) PrettyPrint

func (ql *QueryLog) PrettyPrint(writer io.Writer)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL