mirror of
https://github.com/arnaucube/go-dvote.git
synced 2026-02-28 05:26:46 +01:00
Create new data type for exporting PubSub types
Signed-off-by: p4u <p4u@dabax.net>
This commit is contained in:
12
data/data.go
12
data/data.go
@@ -1,13 +1,18 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"fmt"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
shell "github.com/ipfs/go-ipfs-api"
|
shell "github.com/ipfs/go-ipfs-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Record struct {
|
||||||
|
Shell *shell.Message
|
||||||
|
}
|
||||||
|
|
||||||
func Publish(object []byte) string {
|
func Publish(object []byte) string {
|
||||||
sh := shell.NewShell("localhost:5001")
|
sh := shell.NewShell("localhost:5001")
|
||||||
cid, err := sh.Add(bytes.NewBuffer(object))
|
cid, err := sh.Add(bytes.NewBuffer(object))
|
||||||
@@ -21,13 +26,12 @@ func Publish(object []byte) string {
|
|||||||
func Pin(path string) {
|
func Pin(path string) {
|
||||||
sh := shell.NewShell("localhost:5001")
|
sh := shell.NewShell("localhost:5001")
|
||||||
err := sh.Pin(path)
|
err := sh.Pin(path)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %s", err)
|
fmt.Fprintf(os.Stderr, "error: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Retrieve(hash string) []byte {
|
func Retrieve(hash string) []byte {
|
||||||
sh := shell.NewShell("localhost:5001")
|
sh := shell.NewShell("localhost:5001")
|
||||||
reader, err := sh.Cat(hash)
|
reader, err := sh.Cat(hash)
|
||||||
|
|||||||
15
net/net.go
15
net/net.go
@@ -3,25 +3,24 @@ package net
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"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/batch"
|
||||||
|
"github.com/vocdoni/dvote-relay/data"
|
||||||
|
"github.com/vocdoni/dvote-relay/types"
|
||||||
|
)
|
||||||
|
|
||||||
func Sub(topic string) error {
|
func Sub(topic string) error {
|
||||||
subscription := data.PsSubscribe(topic)
|
subscription := data.PsSubscribe(topic)
|
||||||
fmt.Println("Subscribed > " + topic)
|
fmt.Println("Subscribed > " + topic)
|
||||||
var msg shell.PubSubRecord
|
var msg data.Record
|
||||||
var err error
|
var err error
|
||||||
for {
|
for {
|
||||||
msg, err = subscription.Next()
|
msg.Shell, err = subscription.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := msg.Data()
|
payload := msg.Shell.Data
|
||||||
|
|
||||||
var e types.Envelope
|
var e types.Envelope
|
||||||
var b types.Ballot
|
var b types.Ballot
|
||||||
|
|||||||
Reference in New Issue
Block a user