msg.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package proto
  2. import (
  3. "encoding/json"
  4. "reflect"
  5. )
  6. var TypeMap map[string]reflect.Type
  7. const (
  8. Version = "0.1"
  9. )
  10. func init() {
  11. TypeMap = make(map[string]reflect.Type)
  12. t := func(obj interface{}) reflect.Type { return reflect.TypeOf(obj).Elem() }
  13. TypeMap["RegMsg"] = t((*RegMsg)(nil))
  14. TypeMap["RegAckMsg"] = t((*RegAckMsg)(nil))
  15. TypeMap["RegProxyMsg"] = t((*RegProxyMsg)(nil))
  16. TypeMap["ReqProxyMsg"] = t((*ReqProxyMsg)(nil))
  17. TypeMap["PingMsg"] = t((*PingMsg)(nil))
  18. TypeMap["PongMsg"] = t((*PongMsg)(nil))
  19. TypeMap["VerisonMsg"] = t((*VersionMsg)(nil))
  20. TypeMap["VersionRespMsg"] = t((*VersionRespMsg)(nil))
  21. TypeMap["MetricsMsg"] = t((*MetricsMsg)(nil))
  22. TypeMap["MetricsRespMsg"] = t((*MetricsRespMsg)(nil))
  23. }
  24. type Message interface {
  25. GetType() string
  26. SetType(string)
  27. }
  28. type Envelope struct {
  29. Version string
  30. Type string
  31. Payload json.RawMessage
  32. }
  33. type TypeEmbed struct {
  34. Type string
  35. }
  36. type RegMsg struct {
  37. TypeEmbed
  38. Protocol string
  39. Hostname string
  40. Subdomain string
  41. ClientId string
  42. HttpAuthUser string
  43. HttpAuthPassword string
  44. User string
  45. Password string
  46. OS string
  47. Arch string
  48. }
  49. type RegAckMsg struct {
  50. TypeEmbed
  51. Type string
  52. Url string
  53. ProxyAddr string
  54. Error string
  55. }
  56. type RegProxyMsg struct {
  57. TypeEmbed
  58. Url string
  59. }
  60. type ReqProxyMsg struct {
  61. TypeEmbed
  62. }
  63. type PingMsg struct {
  64. TypeEmbed
  65. }
  66. type PongMsg struct {
  67. TypeEmbed
  68. }
  69. type VersionMsg struct {
  70. TypeEmbed
  71. }
  72. type VersionRespMsg struct {
  73. TypeEmbed
  74. Version string
  75. }
  76. type MetricsMsg struct {
  77. TypeEmbed
  78. }
  79. type MetricsRespMsg struct {
  80. TypeEmbed
  81. Metrics string
  82. }
  83. func (m *TypeEmbed) GetType() string {
  84. return m.Type
  85. }
  86. func (m *TypeEmbed) SetType(typ string) {
  87. m.Type = typ
  88. }