Files

49 lines
901 B
Go
Raw Permalink Normal View History

2019-12-03 20:25:22 +08:00
package main
import (
2019-12-08 00:29:00 +08:00
"C"
2020-01-08 21:57:14 +08:00
"ehang.io/nps/client"
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/version"
2019-12-04 18:36:29 +08:00
"github.com/astaxie/beego/logs"
2019-12-03 20:25:22 +08:00
)
2019-12-04 01:54:23 +08:00
var cl *client.TRPClient
2019-12-03 20:25:22 +08:00
2019-12-04 01:54:23 +08:00
//export StartClientByVerifyKey
2019-12-04 18:36:29 +08:00
func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
_ = logs.SetLogger("store")
2019-12-04 01:54:23 +08:00
if cl != nil {
cl.Close()
}
cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil, 60)
cl.Start()
2019-12-04 18:36:29 +08:00
return 1
2019-12-03 20:25:22 +08:00
}
2019-12-04 01:54:23 +08:00
//export GetClientStatus
2019-12-04 18:36:29 +08:00
func GetClientStatus() int {
2019-12-08 21:04:27 +08:00
return client.NowStatus
2019-12-04 01:54:23 +08:00
}
//export CloseClient
func CloseClient() {
2019-12-08 23:31:53 +08:00
if cl != nil {
cl.Close()
}
2019-12-04 01:54:23 +08:00
}
2019-12-08 00:29:00 +08:00
//export Version
func Version() *C.char {
return C.CString(version.VERSION)
}
2019-12-08 21:04:27 +08:00
2019-12-08 15:46:33 +08:00
//export Logs
2019-12-08 00:29:00 +08:00
func Logs() *C.char {
return C.CString(common.GetLogMsg())
}
2019-12-03 20:25:22 +08:00
func main() {
// Need a main function to make CGO compile package as C shared library
}