clickhouse-go
clickhouse-go copied to clipboard
Allow use HTTP protocol with default API interface
Currently, it's not possible to use HTTP protocol with default "API" interface. This means HTTP support will be marked as non-experimental.
Hello, I can provide solution with another implementation of Conn interface
. I'd like to create clickhouseHttp
struct that has methods and fields identical to default clickhouse
structure.
So in suggested implementation we will have such structure with provided by Conn interface
methods:
type clickhouseHttp struct {
opt *Options
idle chan *httpConnect
open chan struct{}
exit chan struct{}
connID int64
}
Also in this solution we will modify Open func
in such way:
switch o.Protocol {
case HTTP:
conn := &clickhouseHttp{...}
return conn, nil
case Native:
conn := &clickhouse{...}
go conn.startAutoCloseIdleConnections()
return conn, nil
default:
return nil, fmt.Errorf("clickhouse: invalid protocol")
}
But one moment is not clear for me, implementation of method ServerVersion
will look like
func (ch *clickhouseHttp) ServerVersion() (*driver.ServerVersion, error) {
var (
ctx, cancel = context.WithTimeout(context.Background(), ch.opt.DialTimeout)
conn, err = ch.acquire(ctx)
)
defer cancel()
...
version, err := conn.readVersion(ctx)
...
return &driver.ServerVersion{
Version: version,
Timezone: conn.location,
}, nil
}
It is possible solution? Or it will be better to inject ServerVersion
inside httpConnect
struct
If such solution looks good, I'd like to work on this issue.
@loikx feel free to work on it and submit PR. Thanks!