controller.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. // Copyright 2019 github.com. All rights reserved.
  4. // Use of this source code is governed by github.com.
  5. package v1
  6. import (
  7. json2 "encoding/json"
  8. )
  9. const (
  10. GateProtocolSaiboHttpV1 = 1
  11. GateProtocolSaiboMqttV1 = 2
  12. GateProtocolYufanHttpV1 = 3
  13. )
  14. var GateProtocolNameMap = map[int32]string{
  15. GateProtocolSaiboHttpV1: "赛伯罗斯 http v1",
  16. GateProtocolSaiboMqttV1: "赛伯罗斯 mqtt v1",
  17. GateProtocolYufanHttpV1: "宇泛 http v1",
  18. }
  19. // 替换encoding/json包
  20. type JsonStruct struct {
  21. }
  22. func (p *JsonStruct) MarshalToString(v interface{}) (string, error) {
  23. bytes, err := json2.Marshal(v)
  24. return string(bytes), err
  25. }
  26. func (p *JsonStruct) Marshal(v interface{}) ([]byte, error) {
  27. bytes, err := json2.Marshal(v)
  28. return bytes, err
  29. }
  30. func (p *JsonStruct) Unmarshal(bytes []byte, v interface{}) error {
  31. err := json2.Unmarshal(bytes, v)
  32. return err
  33. }
  34. var json = &JsonStruct{}
  35. // Controller
  36. type Controller struct {
  37. }
  38. // NewController return a new controller
  39. func NewController() *Controller {
  40. return &Controller{}
  41. }