Skip to content

koron-go/materialize

Repository files navigation

koron-go/materialize

PkgGoDev Actions/Go Go Report Card

Component's dependencies separator

Gettings started

At first, register a factory of *sql.DB as component.

import "github.com/koron-go/materialize"

materialize.MustAdd(func() (*sql.DB, error) {
  return sql.Open(os.Getenv("DB_DRIVER"), os.Getenv("DB_DATASOURCE_NAME"))
})

Then, obtain a *sql.DB instance when you use. The instance will be created automatically, and managed as singleton.

var db *sql.DB
err := materialize.Materialize(&db)
if err != nil {
  return err
}
// TODO: let's work with "db".

All materiazlied instances which implement Close() error or Close() method, will be closed when you call materialize.CloseAll().

materialize.CloseAll()

About

component's dependency separator

Resources

License

Stars

Watchers

Forks

Packages

No packages published