Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadFromEnv ¶ added in v0.1.9
func LoadFromEnv() error
Example ¶
ExampleLoadFromEnv shows the typical call-site pattern for LoadFromEnv. It reads PostgreSQL connection parameters from the koanf env singleton (keys: db.host, db.port, db.name, db.schema, db.username, db.password, …) and initialises the package-level default pool via postgres.InitDefault.
LoadFromEnv performs an eager connectivity check: if the database is unreachable the error is returned immediately so the application can fail fast at startup rather than on the first real query.
postgres.InitDefault uses sync.Once — only the first call in a process takes effect. Subsequent calls (including calls from other tests in this binary) are no-ops and return nil. For this reason the example does not assert the return value: its primary purpose is to document the call site pattern.
package main
import (
"github.com/phcp-tech/common-library-golang/dbsqlc/postgres/loader"
)
func main() {
err := loader.LoadFromEnv()
// err is non-nil on first call with unreachable DB;
// nil on subsequent calls (sync.Once no-op).
_ = err
}
Output:
Types ¶
This section is empty.