sdk.go 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "C"
  4. "ehang.io/nps/client"
  5. "ehang.io/nps/lib/common"
  6. "ehang.io/nps/lib/version"
  7. "github.com/astaxie/beego/logs"
  8. )
  9. var cl *client.TRPClient
  10. //export StartClientByVerifyKey
  11. func StartClientByVerifyKey(serverAddr, verifyKey, connType, proxyUrl *C.char) int {
  12. _ = logs.SetLogger("store")
  13. if cl != nil {
  14. cl.Close()
  15. }
  16. cl = client.NewRPClient(C.GoString(serverAddr), C.GoString(verifyKey), C.GoString(connType), C.GoString(proxyUrl), nil, 60)
  17. cl.Start()
  18. return 1
  19. }
  20. //export GetClientStatus
  21. func GetClientStatus() int {
  22. return client.NowStatus
  23. }
  24. //export CloseClient
  25. func CloseClient() {
  26. if cl != nil {
  27. cl.Close()
  28. }
  29. }
  30. //export Version
  31. func Version() *C.char {
  32. return C.CString(version.VERSION)
  33. }
  34. //export Logs
  35. func Logs() *C.char {
  36. return C.CString(common.GetLogMsg())
  37. }
  38. func main() {
  39. // Need a main function to make CGO compile package as C shared library
  40. }