AT Protocol IPLD-CAR Repository toolkit (CLI)
1package cli
2
3import (
4 "fmt"
5 "io"
6 "log"
7 "os"
8
9 "github.com/atscan/atr/repo"
10 jsoniter "github.com/json-iterator/go"
11)
12
13type ObjectOutput struct {
14 Did string `json:"did"`
15 Rkey string `json:"rkey"`
16 Cid string `json:"cid"`
17 Body interface{} `json:"body"`
18 Match interface{} `json:"-"`
19}
20
21func Print(v interface{}, ri repo.RepoItem, rs repo.RepoSnapshot) error {
22
23 json, err := jsoniter.Marshal(v)
24 if err != nil {
25 log.Fatal(err)
26 }
27 s := string(json)
28 if s == "null" {
29 return nil
30 }
31 fmt.Println(string(json))
32 return nil
33}
34
35func PrettyPrint(v interface{}, ri repo.RepoItem, rs repo.RepoSnapshot, hg func(io.Writer, string)) error {
36
37 json, err := jsoniter.MarshalIndent(v, "", " ")
38 if err != nil {
39 log.Fatal(err)
40 }
41 s := string(json)
42 if s == "null" {
43 return nil
44 }
45 hg(os.Stdout, s+"\n")
46 return nil
47}