Rest.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package bus
  2. import (
  3. "reflect"
  4. "github.com/gin-gonic/gin"
  5. "github.com/yuguorong/go/log"
  6. )
  7. type RestAppInfo struct {
  8. AppID string
  9. AppSecret string
  10. }
  11. type RestApi struct {
  12. baseBus
  13. router *gin.Engine
  14. port int
  15. mapApp map[string]*RestAppInfo
  16. }
  17. func (rest *RestApi) Init() error {
  18. log.Info("REST module init.")
  19. rest.router = gin.Default()
  20. //router.GET("/Gateway4G/UpdateDevcie", hello) // hello函数处理"/hello"请求
  21. // 指定地址和端口号
  22. go rest.router.Run(":10001")
  23. return nil
  24. }
  25. func (rest *RestApi) Uninit() {
  26. }
  27. func (rest *RestApi) OpenChannel(chnID interface{}, router []chan interface{}) IChannel {
  28. if reflect.TypeOf(chnID).Kind() != reflect.String {
  29. log.Error("wrong channel type, REST URL need a string!")
  30. return nil
  31. }
  32. url := chnID.(string)
  33. log.Info("Rest channel:", url)
  34. return nil
  35. }
  36. func (rest *RestApi) CloseChannel(chn IChannel) error {
  37. return nil
  38. }
  39. func (rest *RestApi) ResetChannel(chn IChannel) {
  40. }
  41. func (rest *RestApi) ScanChannel(stream []byte, conn int) IChannel {
  42. return nil
  43. }
  44. func (rest *RestApi) Send(chn IChannel, buff interface{}) (int, error) {
  45. return 0, nil
  46. }
  47. func (rest *RestApi) Recive(chn IChannel, buff interface{}) (int, error) {
  48. return 0, nil
  49. }