forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (33 loc) · 751 Bytes
/
main.go
File metadata and controls
39 lines (33 loc) · 751 Bytes
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
package main
import (
"bytes"
"encoding/json"
"fmt"
"os"
)
type Out struct {
Files []File `json:"files"`
}
type File struct {
Name string `json:"name"`
Contents []byte `json:"contents"`
}
func main() {
in := make(map[string]interface{})
decoder := json.NewDecoder(os.Stdin)
err := decoder.Decode(&in)
if err != nil {
fmt.Fprintf(os.Stderr, "error generating JSON: %s", err)
os.Exit(2)
}
buf := bytes.NewBuffer(nil)
queries := in["queries"].([]interface{})
for _, q := range queries {
text := q.(map[string]interface{})["text"].(string)
buf.WriteString(text)
buf.WriteString("\n")
}
e := json.NewEncoder(os.Stdout)
e.SetIndent("", " ")
e.Encode(&Out{Files: []File{{Name: "hello.txt", Contents: buf.Bytes()}}})
}