Skip to content

Monorepo 1.0.0

Compare
Choose a tag to compare
@insomnius insomnius released this 10 Feb 15:38
· 12 commits to main since this release
c685992

v1.0.0 is Here!

In this version you could use some of the packages that we're developing which we will describe in this release:

Command

Command is a wrapper for cobra.Command. Usage:

// fabricating command
cmd := command.Fabricate(command.Config{
	Name:  "altair",
	Short: "Open Source API-Gateway",
})

DB

DB is a wrapper for any sql.DB which support better unit test functionality and centralized connection control.

// fabricating db
config := db.Config{
	Username: "root",
	Password: "rootpw",
	Host:     "localhost",
	Port:     "3306",
	Name:     "test_database",
}

sqldb, err := db.FabricateMySQL("main_db", config, db.WithConnMaxLifetime(time.Second), db.WithMaxIdleConn(100), db.WithMaxOpenConn(100))


// next time you open connection, it will return previously created connection instead of creating a new one
sqldb, err := db.FabricateMySQL("main_db", config, db.WithConnMaxLifetime(time.Second), db.WithMaxIdleConn(100), db.WithMaxOpenConn(100))


// close all database connection
db.CloseAll()

MemoryStore

MemoryStore is a wrapper for any cache implementation, currently only supporting memcached. But in the future it will also support redis, keydb and other helpful stack.

// fabricate new memcached
memcached := memorystore.FabricateMemcached("main_cache", memorystore.Config{})

Exception

Golang rich error wrapper

// throw new exception

err := errors.New("unexpected error")
exceptionType := exception.NotFound
detail := "data not found in the databases because of deletion"
title := "data is not exists"

exc := exception.Throw(err, exception.WithType(exceptionType), exception.WithTitle(title), exception.WithDetail(detail))


if exc.Type() == exception.NotFound {
  fmt.Println("The data is not found")
}

Context

Golang rich context wrapper

// create new kontext
ctx := context.Background()
ktx := kontext.Fabricate(kontext.WithDefaultContext(ctx))

// pass context in your function and it will keep the variable it gets along the way
key := "some-value"
val := 100
ktx.Set(key, val)

returnedValue, exists := ktx.Get(key)

What's Next?

  1. Distributed rate limiter package
  2. In-app Queue
  3. In-app Cronjob