arnaucube
arnaucube/go-dvotePublic Self-hosted repository
Merge pull request #18 from vocdoni/hotfix/data-record-type

Create new data type for exporting PubSub types
Pau pau@dabax.net
Wed, 23 Jan 2019 16:57:03 +0100
commit

0e4c0cb8dbeeba32f888ee38e4e97f78ac83fe99

parent

6c1305115e3dabf63d8dba08513d2769d8d9418d

2 files changed, 13 insertions(+), 10 deletions(-)

jump to
M data/data.go → data/data.go

@@ -1,13 +1,18 @@

package data import ( - "os" + "bytes" "fmt" - "bytes" "io/ioutil" + "os" + shell "github.com/ipfs/go-ipfs-api" ) +type Record struct { + Shell *shell.Message +} + func Publish(object []byte) string { sh := shell.NewShell("localhost:5001") cid, err := sh.Add(bytes.NewBuffer(object))

@@ -21,12 +26,11 @@

func Pin(path string) { sh := shell.NewShell("localhost:5001") err := sh.Pin(path) - if err != nil{ + if err != nil { fmt.Fprintf(os.Stderr, "error: %s", err) os.Exit(1) } } - func Retrieve(hash string) []byte { sh := shell.NewShell("localhost:5001")
M net/net.go → net/net.go

@@ -3,25 +3,24 @@

import ( "encoding/json" "fmt" + "github.com/vocdoni/dvote-relay/batch" - "github.com/vocdoni/dvote-relay/types" "github.com/vocdoni/dvote-relay/data" - shell "github.com/ipfs/go-ipfs-api" + "github.com/vocdoni/dvote-relay/types" ) - func Sub(topic string) error { subscription := data.PsSubscribe(topic) fmt.Println("Subscribed > " + topic) - var msg shell.PubSubRecord + var msg data.Record var err error for { - msg, err = subscription.Next() + msg.Shell, err = subscription.Next() if err != nil { return err } - payload := msg.Data() + payload := msg.Shell.Data var e types.Envelope var b types.Ballot