monitoring/app/storage/clickhouse/client.go
Egor Matveev 6e257edcc0
All checks were successful
Deploy Dev / Push (pull_request) Successful in 37s
Deploy Dev / Build (pull_request) Successful in 1m13s
Deploy Dev / Deploy dev (pull_request) Successful in 13s
intiail
2025-06-13 00:25:14 +03:00

49 lines
894 B
Go

package storage
import (
"context"
"crypto/tls"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)
var Connection driver.Conn
func Connect() error {
conn, err := connect()
if err != nil {
return err
}
Connection = *conn
return nil
}
func connect() (*driver.Conn, error) {
var (
ctx = context.Background()
conn, err = clickhouse.Open(&clickhouse.Options{
Addr: []string{"clickhouse:9440"},
Auth: clickhouse.Auth{
Database: "monitoring",
Username: "default",
},
TLS: &tls.Config{
InsecureSkipVerify: true,
},
})
)
if err != nil {
return nil, err
}
if err := conn.Ping(ctx); err != nil {
if exception, ok := err.(*clickhouse.Exception); ok {
fmt.Printf("Exception [%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace)
}
return nil, err
}
return &conn, nil
}