-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapi.go
55 lines (49 loc) · 1.01 KB
/
capi.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
package main
import "C"
import (
"strings"
)
//go build -buildmode=c-archive -o libxdb.a
//go build -buildmode=c-shared -o lib.dylib
type ApiRes struct {
Cost int64 `json:"cost"`
Count int `json:"count"`
Datas [][]string `json:"datas"`
}
//export XdbInit
func XdbInit(params_ *C.char) *C.char {
params := C.GoString(params_)
arr := strings.Split(params, ",")
// fmt.Println(C.GoString(params_))
host = arr[0]
port = ToInt(arr[1])
pwd = arr[2]
dbMinPoolSize = ToInt(arr[3])
dbMaxPoolSize = ToInt(arr[4])
dbMaxWaitSize = ToInt(arr[5])
dbAcq = ToInt(arr[6])
e := initSSDB()
if e != nil {
return C.CString(e.Error())
}
return C.CString("")
}
//export XdbClose
func XdbClose() {
Close()
}
//export Xdb
func Xdb(buf *C.char) *C.char {
silence = true
param := C.GoString(buf)
t0 := CurMills()
c, res, e := xdb(param)
if e != nil {
return C.CString(AppendJson("err", e.Error()))
}
t1 := CurMills()
cost := t1 - t0
apiRes := &ApiRes{cost, c, res}
r := ObjToJsonStr(apiRes)
return C.CString(r)
}