Skip to content

Commit

Permalink
fix(examples): correct file name (#13)
Browse files Browse the repository at this point in the history
* fix(examples): correct file name

The proper naming convention for example files
is *_test.go so that they can be ran like tests.

* test: add non-present field example
  • Loading branch information
wazazaby authored Dec 30, 2023
1 parent ed7f29e commit 8b16952
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/json.go → examples/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Person struct {
Age gonull.Nullable[MyCustomInt] `json:"age"`
Address gonull.Nullable[string] `json:"address"`
Height gonull.Nullable[MyCustomFloat32] `json:"height"`
HasPet gonull.Nullable[bool] `json:"has_pet"`
}

func Example() {
Expand All @@ -34,6 +35,9 @@ func Example() {
// Same for the height.
fmt.Printf("Person.Height is valid: %t, present: %t\n", person.Height.Valid, person.Height.Present)

// HasPet is not present.
fmt.Printf("Person.HasPet is valid: %t, present: %t\n", person.HasPet.Valid, person.HasPet.Present)

marshalledData, err := json.Marshal(person)
if err != nil {
panic(err)
Expand All @@ -45,5 +49,6 @@ func Example() {
// Person.Age is valid: true, present: true
// Person.Address is valid: false, present: true
// Person.Height is valid: false, present: true
// {"name":"Alice","age":15,"address":null,"height":null}
// Person.HasPet is valid: false, present: false
// {"name":"Alice","age":15,"address":null,"height":null,"has_pet":null}
}

0 comments on commit 8b16952

Please sign in to comment.