-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
58 lines (51 loc) · 1.06 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package analytics
import (
"context"
"github.com/ClickHouse/clickhouse-go/v2"
"time"
)
type Client struct {
client clickhouse.Conn
}
func NewClient(client clickhouse.Conn) *Client {
return &Client{
client,
}
}
func Connect(address string, connections int, database, username, password string, readTimeout time.Duration) *Client {
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{address},
Auth: clickhouse.Auth{
Database: database,
Username: username,
Password: password,
},
Compression: &clickhouse.Compression{
Method: clickhouse.CompressionLZ4,
},
DialTimeout: readTimeout,
MaxOpenConns: connections,
MaxIdleConns: connections,
ReadTimeout: readTimeout,
ClientInfo: clickhouse.ClientInfo{
Products: []struct {
Name string
Version string
}{
{
Name: "tickets-analytics",
Version: "0.1",
},
},
},
})
if err != nil { // Infallible
panic(err)
}
return &Client{
client: conn,
}
}
func (c *Client) Ping(context context.Context) error {
return c.client.Ping(context)
}