From d4a3d3f2ffe90769448723e83966b97d690275b1 Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Sun, 28 Jul 2024 01:08:41 +0200 Subject: [PATCH] Use a single main package Move all examples to a single main package so it's easier to run them and more Go idiomatic. --- examples/infer_multiple_string_rows.go | 20 ------------ examples/infer_simple_value.go | 17 ----------- examples/{infer_with_hints.go => main.go} | 37 +++++++++++++++++++++-- 3 files changed, 35 insertions(+), 39 deletions(-) delete mode 100644 examples/infer_multiple_string_rows.go delete mode 100644 examples/infer_simple_value.go rename examples/{infer_with_hints.go => main.go} (54%) diff --git a/examples/infer_multiple_string_rows.go b/examples/infer_multiple_string_rows.go deleted file mode 100644 index fe08148..0000000 --- a/examples/infer_multiple_string_rows.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "encoding/json" - - "github.com/bombsimon/jtd-infer-go" -) - -func main() { - rows := []string{ - `{"name":"Joe", "age": 52, "something_optional": true, "something_nullable": 1.1}`, - `{"name":"Jane", "age": 48, "something_nullable": null}`, - } - schema := jtdinfer. - InferStrings(rows, jtdinfer.WithoutHints()). - IntoSchema() - - j, _ := json.MarshalIndent(schema, "", " ") - print(string(j)) -} diff --git a/examples/infer_simple_value.go b/examples/infer_simple_value.go deleted file mode 100644 index b0c0bc6..0000000 --- a/examples/infer_simple_value.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "encoding/json" - - "github.com/bombsimon/jtd-infer-go" -) - -func main() { - schema := jtdinfer. - NewInferrer(jtdinfer.WithoutHints()). - Infer("my-string"). - IntoSchema() - - j, _ := json.MarshalIndent(schema, "", " ") - print(string(j)) -} diff --git a/examples/infer_with_hints.go b/examples/main.go similarity index 54% rename from examples/infer_with_hints.go rename to examples/main.go index 46edf17..9174782 100644 --- a/examples/infer_with_hints.go +++ b/examples/main.go @@ -2,11 +2,43 @@ package main import ( "encoding/json" + "fmt" - "github.com/bombsimon/jtd-infer-go" + jtdinfer "github.com/bombsimon/jtd-infer-go" ) func main() { + inferSimpleValue() + inferMultipleStringRows() + inferWithHints() +} + +func inferSimpleValue() { + schema := jtdinfer. + NewInferrer(jtdinfer.WithoutHints()). + Infer("my-string"). + IntoSchema() + + j, _ := json.MarshalIndent(schema, "", " ") + fmt.Println(string(j)) + fmt.Println() +} + +func inferMultipleStringRows() { + rows := []string{ + `{"name":"Joe", "age": 52, "something_optional": true, "something_nullable": 1.1}`, + `{"name":"Jane", "age": 48, "something_nullable": null}`, + } + schema := jtdinfer. + InferStrings(rows, jtdinfer.WithoutHints()). + IntoSchema() + + j, _ := json.MarshalIndent(schema, "", " ") + fmt.Println(string(j)) + fmt.Println() +} + +func inferWithHints() { rows := []string{ `{ "name":"Joe", @@ -32,5 +64,6 @@ func main() { schema := jtdinfer.InferStrings(rows, hints).IntoSchema() j, _ := json.MarshalIndent(schema, "", " ") - print(string(j)) + fmt.Println(string(j)) + fmt.Println() }