Documentation ¶
Overview ¶
Package lazy allows for lazily-initialized variables via New(). These are often used for globals representing dependencies. The following example shows how to use enve and lazy to configure and initialize a postgres database using github.com/lib/pq.
import ( "gitlab.com/efronlicht/estd/enve" "gitlab.com/efronlicht/estd/lazy" "database/sql" _ "github.com/lib/pq" // register postgres sql driver ) var Postgres = lazy.New[*sql.DB](lazy.Unwrap(func() *sql.DB, error) { return sql.Open("postgres", pgConnStrFromEnv()) }) func pgConnStrFromEnv() string const ( defaultUser = "efron" defaultDBName = "examples" defaultSSLMode = "require" ) return fmt.Sprintf("user=%s dbname=%s sslmode=%s", enve.StringOr("PG_USER", defaultUser), enve.StringOr("PG_DBNAME", defaultDB), enve.StringOr("sslmode", defaultSSL), ) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.