mirror of
https://github.com/arnaucube/go-dvote.git
synced 2026-02-28 05:26:46 +01:00
add ipfs pubsub methods
This commit is contained in:
23
data/data.go
23
data/data.go
@@ -8,7 +8,7 @@ import (
|
||||
shell "github.com/ipfs/go-ipfs-api"
|
||||
)
|
||||
|
||||
func publish(object []byte) (string) {
|
||||
func publish(object []byte) string {
|
||||
sh := shell.NewShell("localhost:5001")
|
||||
cid, err := sh.Add(bytes.NewBuffer(object))
|
||||
if err != nil {
|
||||
@@ -28,7 +28,7 @@ func pin(path string) {
|
||||
}
|
||||
|
||||
|
||||
func retrieve(hash string) ([]byte){
|
||||
func retrieve(hash string) []byte {
|
||||
sh := shell.NewShell("localhost:5001")
|
||||
reader, err := sh.Cat(hash)
|
||||
if err != nil {
|
||||
@@ -42,3 +42,22 @@ func retrieve(hash string) ([]byte){
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
func PsSubscribe(topic string) *shell.PubSubSubscription {
|
||||
sh := shell.NewShell("localhost:5001")
|
||||
sub, err := sh.PubSubSubscribe(topic)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return sub
|
||||
}
|
||||
|
||||
func PsPublish(topic, data string) {
|
||||
sh := shell.NewShell("localhost:5001")
|
||||
err := sh.PubSubPublish(topic, data)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user