From 8bd2b1aceaf542f271c04ea294df7f60f8794869 Mon Sep 17 00:00:00 2001 From: p4u Date: Wed, 23 Jan 2019 16:41:49 +0100 Subject: [PATCH] Create new data type for exporting PubSub types Signed-off-by: p4u --- data/data.go | 12 ++++++++---- net/net.go | 11 +++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/data/data.go b/data/data.go index 5f56f31..036ee67 100644 --- a/data/data.go +++ b/data/data.go @@ -1,13 +1,18 @@ package data import ( - "os" - "fmt" "bytes" + "fmt" "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,13 +26,12 @@ func Publish(object []byte) string { 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") reader, err := sh.Cat(hash) diff --git a/net/net.go b/net/net.go index f1585e8..22f7e43 100644 --- a/net/net.go +++ b/net/net.go @@ -3,25 +3,24 @@ package net 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