From ebaf83e2e150d2b0d53fd9294e961be99c497812 Mon Sep 17 00:00:00 2001 From: Teddy Sommavilla Date: Sat, 30 Dec 2023 18:40:52 +0100 Subject: [PATCH 1/2] fix(examples): correct file name The proper naming convention for example files is *_test.go so that they can be ran like tests. --- examples/{json.go => json_test.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{json.go => json_test.go} (100%) diff --git a/examples/json.go b/examples/json_test.go similarity index 100% rename from examples/json.go rename to examples/json_test.go From cd8ac9911e53e3b8379ed097f886046e0b629042 Mon Sep 17 00:00:00 2001 From: Teddy Sommavilla Date: Sat, 30 Dec 2023 18:43:10 +0100 Subject: [PATCH 2/2] test: add non-present field example --- examples/json_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/json_test.go b/examples/json_test.go index 34ebfc2..2a0a91f 100644 --- a/examples/json_test.go +++ b/examples/json_test.go @@ -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() { @@ -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) @@ -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} }