@@ -22,15 +22,26 @@ func OpenClickHouseConn() (*sql.DB, *Config, error) {
22
22
if err != nil {
23
23
return nil , nil , err
24
24
}
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 )
34
45
if err := conn .Ping (); err != nil {
35
46
if exception , ok := err .(* clickhouse.Exception ); ok {
36
47
return nil , nil , fmt .Errorf ("[%d] %s %s" , exception .Code , exception .Message , exception .StackTrace )
0 commit comments