...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package main
19
20 import (
21 "encoding/json"
22 "io"
23
24 "github.com/pelletier/go-toml/v2"
25 "github.com/pelletier/go-toml/v2/internal/cli"
26 )
27
28 const usage = `jsontoml can be used in two ways:
29 Reading from stdin:
30 cat file.json | jsontoml > file.toml
31
32 Reading from a file:
33 jsontoml file.json > file.toml
34 `
35
36 func main() {
37 p := cli.Program{
38 Usage: usage,
39 Fn: convert,
40 }
41 p.Execute()
42 }
43
44 func convert(r io.Reader, w io.Writer) error {
45 var v interface{}
46
47 d := json.NewDecoder(r)
48 err := d.Decode(&v)
49 if err != nil {
50 return err
51 }
52
53 e := toml.NewEncoder(w)
54 return e.Encode(v)
55 }
56
View as plain text