-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclient.go
57 lines (46 loc) · 1.27 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
package ksqldb
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"github.com/thmeitz/ksqldb-go/net"
)
type BodyReader func(io.Reader) ([]byte, error)
type RespUnmarshaller func([]byte, interface{}) error
type KsqldbClient struct {
http net.HTTPClient
parseSQL bool
readBody BodyReader
unMarshalResp RespUnmarshaller
}
// NewClient returns a new KsqldbClient with the given net.HTTPclient
func NewClient(http net.HTTPClient) (KsqldbClient, error) {
var client = KsqldbClient{
http: http,
parseSQL: true,
readBody: ioutil.ReadAll,
unMarshalResp: json.Unmarshal,
}
return client, nil
}
// NewClientWithOptions returns a new @KsqldbClient with Options
func NewClientWithOptions(options net.Options) (KsqldbClient, error) {
http, err := net.NewHTTPClient(options, nil)
if err != nil {
return KsqldbClient{}, fmt.Errorf("%v", err)
}
return NewClient(&http)
}
// EnableParseSQL enables / disables sql parsing
func (cl *KsqldbClient) EnableParseSQL(activate bool) {
cl.parseSQL = activate
}
// ParseSQLEnabled returns true if sql parsing is enabled; false otherwise
func (cl *KsqldbClient) ParseSQLEnabled() bool {
return cl.parseSQL
}
// Close closes the underlying http transport
func (cl *KsqldbClient) Close() {
cl.http.Close()
}