-
Notifications
You must be signed in to change notification settings - Fork 0
/
newPaste.go
69 lines (58 loc) · 1.72 KB
/
newPaste.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
)
type idNewPaste struct {
Ipfs bool `json:"ipfs"`
Hash string `json:"hash"`
UrlId string `json:"url_id"`
}
// to add a paste
type pasteAdd struct {
Event event `json:"event"`
Sender string `json:"sender"`
Data userDataAdd `json:"data"`
}
// informations to set for adding a paste
type userDataAdd struct {
Text string `json:"text"`
Private bool `json:"private"`
Burn bool `json:"burn"`
BurnView int `json:"burn_view"`
Ipfs bool `json:"ipfs"`
ExpirationTime string `json:"expiration_time"`
ExpirationHeight int `json:"expiration_height"`
EncParams encParams `json:"encParams"`
}
func newPaste(text string, encryptionParams encParams, selfAddress string, public bool, ipfs bool, burn bool, burnView int, expirationTime string, expirationHeight int) idNewPaste {
paste := pasteAdd{
Event: newText,
Sender: selfAddress,
Data: userDataAdd{
Text: text,
Private: public,
Burn: burn,
BurnView: burnView,
ExpirationTime: expirationTime,
ExpirationHeight: expirationHeight,
Ipfs: ipfs,
EncParams: encryptionParams,
},
}
receivedMessage := sendTextWithReply(&paste, 0, false)
messageByte := []byte(receivedMessage.Message)
if strings.Contains(strings.ToLower(receivedMessage.Message), "error") {
errMsg := strings.ToLower(receivedMessage.Message)
fmt.Printf("\n\n%s%s%s\n", Red, strings.Replace(errMsg, "\"", "", -1), Reset)
os.Exit(1)
}
var dataUrl idNewPaste
err := json.Unmarshal(messageByte, &dataUrl)
if err != nil {
panic(err)
}
return dataUrl
}