Skip to content

Commit 8e37196

Browse files
committed
fix
1 parent 630e057 commit 8e37196

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

cmd/cli/config/config.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ func OpenClickHouseConn() (*sql.DB, *Config, error) {
2222
if err != nil {
2323
return nil, nil, err
2424
}
25-
conn := clickhouse.OpenDB(&clickhouse.Options{
26-
Addr: []string{
27-
fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
28-
Debug: true,
29-
Auth: clickhouse.Auth{
30-
Username: cfg.ClickHouseUsername,
31-
Password: cfg.ClickHousePassword,
32-
},
33-
})
25+
var conns clickhouse.Options
26+
27+
if cfg.ClickHouseUsername != "" && cfg.ClickHousePassword != "" {
28+
fmt.Println("Using provided username and password")
29+
conns = clickhouse.Options{
30+
Addr: []string{fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
31+
Debug: true,
32+
Auth: clickhouse.Auth{
33+
Username: cfg.ClickHouseUsername,
34+
Password: cfg.ClickHousePassword,
35+
},
36+
}
37+
} else {
38+
fmt.Println("Using connection without username and password")
39+
conns = clickhouse.Options{
40+
Addr: []string{fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
41+
}
42+
}
43+
44+
conn := clickhouse.OpenDB(&conns)
3445
if err := conn.Ping(); err != nil {
3546
if exception, ok := err.(*clickhouse.Exception); ok {
3647
return nil, nil, fmt.Errorf("[%d] %s %s", exception.Code, exception.Message, exception.StackTrace)

0 commit comments

Comments
 (0)