Documentation
¶
Overview ¶
Package component provides ClickHouse lifecycle integration for bootstrap.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Component ¶
func Component() bootstrap.IComponent
Component wraps loadFromEnv as a bootstrap.IComponent. Init calls loadFromEnv; Close closes the default ClickHouse connection.
Because clickhouse-go opens connections lazily, Init() always returns nil. Use a PreReady step with conn.Ping() for an eager connectivity check:
Add(component.Component()).
PreReady(func() error {
return clickhouse.Default().Ping(ctx)
}).
Run()
Example ¶
ExampleComponent shows how Component() is used in a bootstrap registration chain. It reads ClickHouse connection parameters from env during Init():
db.host, db.port, db.name, db.username, db.password
clickhouse-go opens connections lazily — Init() always returns nil. Use a PreReady step with conn.Ping() for an eager connectivity check:
bootstrap.New().
Add(envComp.Component(...)).
Add(logComp.Component()).
Add(dbComp.Component()).
PreReady(func() error {
return clickhouse.Default().Ping(ctx)
}).
Run()
package main
import (
"fmt"
dbComp "github.com/phcp-tech/common-library-golang/dbsqlc/clickhouse/component"
)
func main() {
c := dbComp.Component()
fmt.Println(c != nil)
}
Output: true
Types ¶
This section is empty.