Skip to content

Commit

Permalink
Use a single main package
Browse files Browse the repository at this point in the history
Move all examples to a single main package so it's easier to run them
and more Go idiomatic.
  • Loading branch information
bombsimon committed Jul 27, 2024
1 parent 7ccca52 commit d4a3d3f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 39 deletions.
20 changes: 0 additions & 20 deletions examples/infer_multiple_string_rows.go

This file was deleted.

17 changes: 0 additions & 17 deletions examples/infer_simple_value.go

This file was deleted.

37 changes: 35 additions & 2 deletions examples/infer_with_hints.go → examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
}

0 comments on commit d4a3d3f

Please sign in to comment.