-
-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathq.go
52 lines (42 loc) · 1.21 KB
/
q.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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/ryboe/q"
)
func main() {
// q.Q writes its output to a temp file, you should run "tail -f $TMPDIR/q" in a separate terminal/cli-window
var strings []string
var jsonstring = `["lorem", "ipsum", "dolor", "sit", "amet"]`
// convert json bytes-string to object
err := json.Unmarshal([]byte(jsonstring), &strings)
if err != nil {
fmt.Println("error while unmarshalling")
os.Exit(2)
}
// debug strings variable with q.Q
q.Q(strings)
//convert object to bytes-string
func(str []string) {
jsonData, err := json.Marshal(str)
if err != nil {
fmt.Println("error while marshalling")
os.Exit(2)
}
// debug jsonData variable in an anonymous function with q.Q
q.Q(string(jsonData))
}(strings)
/* you will see something like this in your other terminal/cli-window:
*
* [18:00:00 non-std-lib/q.go:25 main.main]
* 0.000s strings=[]string{"lorem", "ipsum", "dolor", "sit", "amet"}
*
* [18:00:00 non-std-lib/q.go:37 main.main.func1]
* 0.000s string(jsonData)=["lorem","ipsum","dolor","sit","amet"]
*
* it contains infos about the folder, file and function it was executed in,
* the runtime and the data passed to q.Q
*
*/
}