-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
42 lines (36 loc) · 835 Bytes
/
main.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"github.com/pingcap/errors"
"github.com/zyguan/just"
)
func load(p string) (m map[string]interface{}) {
f := just.TryValues(os.Open(p)).Nth(0).(*os.File)
defer f.Close()
bs := just.TryValuesWithMsg("read " + p)(ioutil.ReadAll(f)).Nth(0).([]byte)
just.TryValuesWithMsg("decode " + p)(json.Unmarshal(bs, &m))
return
}
func printAll(ps []string) (err error) {
defer just.Return(&err)
for i, p := range ps {
m := load(p)
bs := just.TryValues(json.Marshal(m)).Nth(0).([]byte)
log.Println(i, string(bs))
}
return
}
func main() {
defer log.Println("# END")
defer just.Catch(func(c just.Catchable) {
log.Printf("# OOPS: %+v", c.Why())
})
log.Println("# BEGIN")
just.TryValues(printAll(os.Args[1:]))
}
func init() {
just.SetTraceFn(errors.Trace)
}