forked from goat-systems/go-tezos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
41 lines (34 loc) · 739 Bytes
/
utils.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
package goTezos
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"strings"
)
//A confirmation dialog, possibly to be used later, not tested.
func askForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("%s [y/n]: ", s)
response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
response = strings.ToLower(strings.TrimSpace(response))
if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
}
}
}
//Takes an interface v and returns a pretty json string.
func PrettyReport(v interface{}) string {
b, err := json.MarshalIndent(v, "", " ")
if err == nil {
return string(b)
}
return ""
}