This repository was archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.go
More file actions
89 lines (71 loc) · 1.65 KB
/
tools.go
File metadata and controls
89 lines (71 loc) · 1.65 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"runtime"
"strings"
)
var Reset = "\033[0m"
var Red = "\033[31m"
var Green = "\033[32m"
var Yellow = "\033[33m"
var Blue = "\033[34m"
var Purple = "\033[35m"
var Cyan = "\033[36m"
var Gray = "\033[37m"
var White = "\033[97m"
type capababilities struct {
IpfsHosting bool `json:"ipfs_hosting"`
ExpirationBitcoinHeight bool `json:"expiration_bitcoin_height"`
}
type pingMessage struct {
Event event `json:"event"`
Sender string `json:"sender"`
Data string `json:"data"`
}
type pingReceived struct {
Version string `json:"version"`
Capabilities capababilities `json:"capabilities"`
Alive bool
}
func extractLink(link string) (string, string) {
var urlId string
urlId = link[strings.LastIndex(link, "/")+1:]
var key string
if strings.Contains(urlId, "&") {
//extract key
key = strings.Replace(urlId[strings.LastIndex(urlId, "&")+1:], "key=", "", -1)
urlId = urlId[:strings.Index(urlId, "&")]
}
return urlId, key
}
func initColor() {
if runtime.GOOS == "windows" {
Reset = ""
Red = ""
Green = ""
Yellow = ""
Blue = ""
Purple = ""
Cyan = ""
Gray = ""
White = ""
}
}
func pingBackend(selfAddress string, testBackendAlive bool) pingReceived {
pingMessage := pingMessage{
Event: ping,
Data: "emtpy",
}
receivedMessage := sendTextWithReply(pingMessage, 8, testBackendAlive)
if receivedMessage.Type == "error" {
return pingReceived{Version: "0.0.0", Alive: false}
} else {
messageByte := []byte(receivedMessage.Message)
var pingData pingReceived
err := json.Unmarshal(messageByte, &pingData)
if err != nil {
panic(err)
}
return pingData
}
}