arnaucube
arnaucube/go-dvotePublic Self-hosted repository
working implementation of modular transports, generator still pubsub only
imw isaac@iwilder.net
Thu, 07 Feb 2019 13:32:49 +0100
commit

7128e24db350dbf73ccf1f9db9d804f62f2256c4

parent

5ce8bb33ee36b46b0306a14fda20f5f7cb2f9afa

4 files changed, 12 insertions(+), 12 deletions(-)

jump to
M cmd/generator/generator.go → cmd/generator/generator.go

@@ -12,7 +12,7 @@ // "net/http"

// "bytes" // "io/ioutil" "github.com/vocdoni/dvote-relay/types" - "github.com/vocdoni/dvote-relay/data" + "github.com/vocdoni/dvote-relay/net" ) func makeBallot() string {

@@ -85,7 +85,7 @@ select {

case <- timer.C: var jsonStr = makeEnvelope(makeBallot()) fmt.Println(jsonStr) - data.PsPublish(topic, jsonStr) + net.PsPublish(topic, jsonStr) default: continue }
M net/http.go → net/http.go

@@ -16,7 +16,7 @@ port string

path string } -func (h HttpHandle) Init(c string) error { +func (h *HttpHandle) Init(c string) error { //split c to port and path cs := strings.Split(c, "/") h.port = cs[0]

@@ -66,11 +66,11 @@ }

io.WriteString(rw, string(j)) } -func (h HttpHandle) Listen() error { +func (h *HttpHandle) Listen() error { http.HandleFunc(h.path, parse) //add waitgroup func() { - fmt.Println("serving on " + h.port) + fmt.Println("serving on " + h.port + "/" + h.path) err := http.ListenAndServe(":" + h.port, nil) if err != nil { return
M net/net.go → net/net.go

@@ -5,8 +5,8 @@ "errors"

) type Transport interface { - Init(c string) error Listen() error + Init(c string) error } type TransportID int

@@ -30,11 +30,11 @@

func Init(t TransportID) (Transport, error) { switch t { case PubSub : - var p PubSubHandle + p := new(PubSubHandle) p.Init("vocdoni_pubsub_testing") return p, nil case HTTP : - var h HttpHandle + h := new(HttpHandle) h.Init("8080/submit") return h, nil default:
M net/pubsub.go → net/pubsub.go

@@ -34,19 +34,19 @@ }

return nil } -func (p PubSubHandle) Init(topic string) error { +func (p *PubSubHandle) Init(topic string) error { p.topic = topic p.subscription = PsSubscribe(p.topic) - fmt.Println("Subscribed > " + p.topic) return nil } -func (p PubSubHandle) Listen() error { +func (p *PubSubHandle) Listen() error { var msg *shell.Message var err error for { msg, err = p.subscription.Next() if err != nil { + fmt.Fprintf(os.Stderr, "recieve error: %s", err) return err }

@@ -74,6 +74,6 @@ fmt.Println("Got > " + string(payload))

} } -func (p PubSubHandle) Send(data string) error { +func (p *PubSubHandle) Send(data string) error { return PsPublish(p.topic, data) }