sdk.go 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "C"
  4. "github.com/astaxie/beego/logs"
  5. "github.com/cnlh/nps/client"
  6. "github.com/cnlh/nps/lib/common"
  7. "github.com/cnlh/nps/lib/version"
  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)
  17. go func() {
  18. cl.Start()
  19. return
  20. }()
  21. return 1
  22. }
  23. //export GetClientStatus
  24. func GetClientStatus() int {
  25. return client.NowStatus
  26. }
  27. //export CloseClient
  28. func CloseClient() {
  29. if cl != nil {
  30. cl.Close()
  31. }
  32. }
  33. //export Version
  34. func Version() *C.char {
  35. return C.CString(version.VERSION)
  36. }
  37. //export Logs
  38. func Logs() *C.char {
  39. return C.CString(common.GetLogMsg())
  40. }
  41. func main() {
  42. // Need a main function to make CGO compile package as C shared library
  43. }