nps/cmd/npc/sdk.go

52 lines
921 B
Go
Raw Normal View History

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