-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.go
54 lines (48 loc) · 1022 Bytes
/
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
// +build !mock
package terago
/*
#cgo LDFLAGS: -ltera_c
#include "c/client.h"
*/
import "C"
import (
"errors"
"fmt"
)
type Client struct {
ConfPath string
CClient *C.tera_client_t
}
func NewClient(conf_path, log_prefix string) (client Client, err error) {
fmt.Println("new client")
c := Client{
CClient: C.client_open(C.CString(conf_path), C.CString(log_prefix)),
ConfPath: conf_path,
}
if c.CClient == nil {
err = errors.New("Fail to create tera client")
} else {
client = c
}
return
}
func (c Client) Close() {
fmt.Println("close client")
if c.CClient != nil {
C.tera_client_close(c.CClient)
}
}
func (c Client) OpenKvStore(name string) (kv KvStore, err error) {
fmt.Println("open table: " + name)
if c.CClient == nil {
err = errors.New("Fail to open table, client not available.")
return
}
c_table := C.table_open(c.CClient, C.CString(name))
if c_table == nil {
err = fmt.Errorf("Fail to open table %s", name)
return
}
kv = KvStore{Name: name, CTable: c_table}
return
}