mongo

package
v0.0.0-...-0f898fb Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForContext

func ForContext(ctx context.Context) *mongo.Client

ForContext is method to get mongodb client from context

Types

type MongoDBHandler

type MongoDBHandler struct {
	Env    config.Env
	Client *mongo.Client
}

MongoDBHandler is connection provider to access to global mongodb client

func NewMongoDatabase

func NewMongoDatabase(cnf config.Env, Logger *zap.Logger) (*MongoDBHandler, error)

func NewMongoDatabase(cnf config.Env, Logger *zap.Logger) (*mongo.Client, error) {

func (*MongoDBHandler) Collection

func (m *MongoDBHandler) Collection(ctx context.Context, col string) (*mongo.Collection, error)

func (*MongoDBHandler) Connect

func (m *MongoDBHandler) Connect() gin.HandlerFunc

Connect is method return adpater for http request that

func (*MongoDBHandler) DeleteUser

func (m *MongoDBHandler) DeleteUser(ctx context.Context, id string) (string, error)

func (*MongoDBHandler) Disconnect

func (dbHandler *MongoDBHandler) Disconnect(ctx context.Context) error

Disconnect is method return adpater for http request that

func (*MongoDBHandler) FindAllUsers

func (m *MongoDBHandler) FindAllUsers(ctx context.Context) ([]*domain.User, error)

func (*MongoDBHandler) FindUserByID

func (m *MongoDBHandler) FindUserByID(ctx context.Context, id string) (*domain.User, error)

func (*MongoDBHandler) SaveUser

func (m *MongoDBHandler) SaveUser(ctx context.Context, newUser domain.NewUser) (*domain.User, error)

func (*MongoDBHandler) WithContext

func (m *MongoDBHandler) WithContext(ctx context.Context) context.Context

WithContext is method apply mongoClient into context

type MongoDbInitProvider

type MongoDbInitProvider interface {
	Disconnect(ctx context.Context) error
	Connect() gin.HandlerFunc
	WithContext(ctx context.Context) context.Context
	Collection(ctx context.Context, col string) (*mongo.Collection, error)
	FindAllUsers(ctx context.Context) ([]*domain.User, error)
	FindUserByID(ctx context.Context, id string) (*domain.User, error)
	SaveUser(ctx context.Context, newUser domain.NewUser) (*domain.User, error)
	DeleteUser(ctx context.Context, id string) (string, error)
}

Jump to

Keyboard shortcuts

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