zerotier_api.go 952 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package zerotier
  2. import (
  3. httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
  4. "github.com/tidwall/gjson"
  5. "net/http"
  6. )
  7. func PostData(url, token string, data string) interface{} {
  8. body, code := httper2.ZeroTierPostJson(url, data, GetHead(token))
  9. if code != http.StatusOK {
  10. return ""
  11. }
  12. result := gjson.Parse(body)
  13. return result.Value()
  14. }
  15. func GetData(url, token string) interface{} {
  16. body, code := httper2.ZeroTierGet(url, GetHead(token))
  17. if code != http.StatusOK {
  18. return ""
  19. }
  20. result := gjson.Parse(body)
  21. return result.Value()
  22. }
  23. func DeleteMember(url, token string) interface{} {
  24. body, code := httper2.ZeroTierDelete(url, GetHead(token))
  25. if code != http.StatusOK {
  26. return ""
  27. }
  28. result := gjson.Parse(body)
  29. return result.Value()
  30. }
  31. func GetHead(token string) map[string]string {
  32. var head = make(map[string]string)
  33. head["Authorization"] = "Bearer " + token
  34. head["Content-Type"] = "application/json"
  35. return head
  36. }