tree.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package model
  2. import (
  3. "net/url"
  4. "reflect"
  5. )
  6. const _query = "query"
  7. // TreeResponse Tree Response.
  8. type TreeResponse struct {
  9. Code int `json:"code"`
  10. Data UserTree `json:"data"`
  11. }
  12. // UserTree User Tree.
  13. type UserTree struct {
  14. Bilibili map[string]interface{} `json:"bilibili"`
  15. }
  16. // TreeMachinesResponse Tree Machines Response.
  17. type TreeMachinesResponse struct {
  18. Code int `json:"code"`
  19. Data []string `json:"data"`
  20. }
  21. // TreeSonResponse Tree Son Response.
  22. type TreeSonResponse struct {
  23. Code int `json:"code"`
  24. Data map[string]interface{} `json:"data"`
  25. }
  26. // TreeRoleResponse Tree Role Response.
  27. type TreeRoleResponse struct {
  28. Code int `json:"code"`
  29. Data []*TreeRole `json:"data"`
  30. }
  31. // TreeInstancesResponse Tree Instance Response.
  32. type TreeInstancesResponse struct {
  33. Code int `json:"code"`
  34. Data map[string]*TreeInstance `json:"data"`
  35. }
  36. // TreeInstance Tree Instance.
  37. type TreeInstance struct {
  38. HostName string `json:"hostname"`
  39. IP string `json:"ip"`
  40. InstanceType string `json:"instance_type"`
  41. InternalIP string `json:"internal_ip"`
  42. ServiceIP string `json:"service_ip"`
  43. ExtendIP string `json:"extend_ip"`
  44. }
  45. // TreeAppInstanceRequest Tree App Instance Request.
  46. type TreeAppInstanceRequest struct {
  47. Paths []string `json:"paths"`
  48. }
  49. // TreeAppInstanceResponse Tree App Instance Response.
  50. type TreeAppInstanceResponse struct {
  51. Code int `json:"code"`
  52. Data map[string][]*TreeAppInstance `json:"data"`
  53. }
  54. // TreeAppInstance Tree App Instance.
  55. type TreeAppInstance struct {
  56. HostName string `json:"hostname"`
  57. }
  58. // TreePlatformTokenRequest Tree Platform Token Request.
  59. type TreePlatformTokenRequest struct {
  60. UserName string `json:"user_name"`
  61. PlatformID string `json:"platform_id"`
  62. }
  63. // TreeRole Tree Role.
  64. type TreeRole struct {
  65. UserName string `json:"user_name"`
  66. Role int `json:"role"`
  67. OldRole int `json:"old_role"`
  68. RdSre bool `json:"rd_sre"`
  69. }
  70. // TreeConf tree conf.
  71. type TreeConf struct {
  72. Host string
  73. Key string
  74. Secret string
  75. }
  76. // TreeInstanceRequest request for hostname.
  77. type TreeInstanceRequest struct {
  78. Path string `query:"path"`
  79. PathFuzzy string `query:"path_fuzzy"`
  80. Hostname string `query:"hostname"`
  81. HostnameFuzzy string `query:"hostname_fuzzy"`
  82. HostnameRegex string `query:"hostname_regex"`
  83. }
  84. // ToQueryURI convert field to uri.
  85. func (tir TreeInstanceRequest) ToQueryURI() string {
  86. var (
  87. params = &url.Values{}
  88. t = reflect.TypeOf(tir)
  89. v = reflect.ValueOf(tir)
  90. fv string
  91. )
  92. for i := 0; i < t.NumField(); i++ {
  93. fv = v.Field(i).Interface().(string)
  94. if fv != "" {
  95. params.Set(t.Field(i).Tag.Get(_query), fv)
  96. }
  97. }
  98. return params.Encode()
  99. }