handlerManager.go 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package iot
  2. import (
  3. "log"
  4. "net/http"
  5. )
  6. /*
  7. IoT Handler Manager
  8. Author: tobychui
  9. This manager mange all the existsing / registered ioT Manager.
  10. This allow a much more abstract usage in the main code
  11. */
  12. type Manager struct {
  13. RegisteredHandler []ProtocolHandler
  14. }
  15. func NewIoTManager() *Manager {
  16. return &Manager{
  17. RegisteredHandler: []ProtocolHandler{},
  18. }
  19. }
  20. //Register the handler as one of the IoT Protocol Handler.
  21. func (m *Manager) RegisterHandler(h ProtocolHandler) error {
  22. //Try to start the handler
  23. err := h.Start()
  24. if err != nil {
  25. //Handler startup failed
  26. log.Println("*IoT* Protocol Handler Startup Failed: ", err.Error())
  27. return err
  28. }
  29. //Add it to the handlers
  30. m.RegisteredHandler = append(m.RegisteredHandler, h)
  31. return nil
  32. }
  33. //Handle IoT Scanning Request
  34. func (m *Manager) HandleScanning(w http.ResponseWriter, r *http.Request) {
  35. }