Skip to content

ch1f/aig

Repository files navigation

AIG - auto-increment generator based on MongoDB

Has backwards compatibility with https://github.com/night-codes/mgo-ai package. The option to connect OpenTelemetry is available.

ENV

AIG_MONGO_URI type: string

URI for connecting to MongoDB, required.

AIG_MONGO_USER type: string

Credentials for connecting to mongodb.

AIG_MONGO_PASSWORD type: string

Credentials for connecting to mongodb.

AIG_MONGO_DB type: string

The name of the database where data about increment will be stored, required.

AIG_MONGO_COLLECTION type: string

The name of the collection where data about increment will be stored, required.

Connection example

import (
	"github.com/ch1f/aig"
	"go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)

// Getting data from env
aigCfg := aig.GetConfigEnv()
// also you can specify them from another source
aigCfg.DB = "aig"
aigCfg.Collection = "aig"

// Connecting the mongodb trace to OpenTelemtry
aigCfg.Monitor = otelmongo.NewMonitor()

// Creating a module. If there is an error connecting to the database, panic will be used inside.
aigModule := aig.Create(ctx, aigCfg)

//So, you can start using incrementation according to method that is backward compatible with mgo-ai
someID := aigModule.Next("some")

//or use new one with tracing
someID := aigModule.Generate(ctx, "some")

About

AIG - auto-increment generator based on MongoDB

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages