msg.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  55. type RegProxyMsg struct {
  56. TypeEmbed
  57. Url string
  58. }
  59. type ReqProxyMsg struct {
  60. TypeEmbed
  61. }
  62. type PingMsg struct {
  63. TypeEmbed
  64. }
  65. type PongMsg struct {
  66. TypeEmbed
  67. }
  68. type VersionMsg struct {
  69. TypeEmbed
  70. }
  71. type VersionRespMsg struct {
  72. TypeEmbed
  73. Version string
  74. }
  75. type MetricsMsg struct {
  76. TypeEmbed
  77. }
  78. type MetricsRespMsg struct {
  79. TypeEmbed
  80. Metrics string
  81. }
  82. func (m *TypeEmbed) GetType() string {
  83. return m.Type
  84. }
  85. func (m *TypeEmbed) SetType(typ string) {
  86. m.Type = typ
  87. }