Skip to content

Commit 2782348

Browse files
committed
Use a single main package
Move all examples to a single main package so it's easier to run them and more Go idiomatic.
1 parent 7ccca52 commit 2782348

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

examples/infer_multiple_string_rows.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/infer_simple_value.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/infer_with_hints.go renamed to examples/main.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,43 @@ package main
22

33
import (
44
"encoding/json"
5+
"fmt"
56

6-
"github.com/bombsimon/jtd-infer-go"
7+
jtdinfer "github.com/bombsimon/jtd-infer-go"
78
)
89

910
func main() {
11+
inferSimpleValue()
12+
inferMultipleStringRows()
13+
inferWithHints()
14+
}
15+
16+
func inferSimpleValue() {
17+
schema := jtdinfer.
18+
NewInferrer(jtdinfer.WithoutHints()).
19+
Infer("my-string").
20+
IntoSchema()
21+
22+
j, _ := json.MarshalIndent(schema, "", " ")
23+
fmt.Println(string(j))
24+
fmt.Println()
25+
}
26+
27+
func inferMultipleStringRows() {
28+
rows := []string{
29+
`{"name":"Joe", "age": 52, "something_optional": true, "something_nullable": 1.1}`,
30+
`{"name":"Jane", "age": 48, "something_nullable": null}`,
31+
}
32+
schema := jtdinfer.
33+
InferStrings(rows, jtdinfer.WithoutHints()).
34+
IntoSchema()
35+
36+
j, _ := json.MarshalIndent(schema, "", " ")
37+
fmt.Println(string(j))
38+
fmt.Println()
39+
}
40+
41+
func inferWithHints() {
1042
rows := []string{
1143
`{
1244
"name":"Joe",
@@ -32,5 +64,6 @@ func main() {
3264

3365
schema := jtdinfer.InferStrings(rows, hints).IntoSchema()
3466
j, _ := json.MarshalIndent(schema, "", " ")
35-
print(string(j))
67+
fmt.Println(string(j))
68+
fmt.Println()
3669
}

0 commit comments

Comments
 (0)