You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
626 B

  1. package net
  2. import (
  3. "errors"
  4. )
  5. type Transport interface {
  6. Listen() error
  7. Init(c string) error
  8. }
  9. type TransportID int
  10. const (
  11. HTTP TransportID = iota + 1
  12. PubSub
  13. )
  14. func TransportIDFromString(i string) TransportID {
  15. switch i {
  16. case "PubSub" :
  17. return PubSub
  18. case "HTTP":
  19. return HTTP
  20. default:
  21. return -1
  22. }
  23. }
  24. func Init(t TransportID) (Transport, error) {
  25. switch t {
  26. case PubSub :
  27. p := new(PubSubHandle)
  28. p.Init("vocdoni_pubsub_testing")
  29. return p, nil
  30. case HTTP :
  31. h := new(HttpHandle)
  32. h.Init("8080/submit")
  33. return h, nil
  34. default:
  35. return nil, errors.New("Bad transport type specification")
  36. }
  37. }