From 0aeff94720db4be1fe055d3ed6e9d2e322706cc2 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Tue, 29 Jul 2014 13:04:37 +0300 Subject: [PATCH] structure: add example for IsValid() --- structure_example_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/structure_example_test.go b/structure_example_test.go index 1243c95..393e9e2 100644 --- a/structure_example_test.go +++ b/structure_example_test.go @@ -97,3 +97,34 @@ func ExampleFields() { // Output: // []string{"LastAccessed", "Name", "Number"} } + +func ExampleIsValid() { + // Let's define an Access struct. Note that the "Enabled" field is not + // going to be checked because we added the "structure" tag to the field. + type Access struct { + Name string + LastAccessed time.Time + Number int + Enabled bool `structure:"-"` + } + + // Name and Number is not initialized. + a := &Access{ + LastAccessed: time.Now(), + } + validA := IsValid(a) + + // Name and Number is initialized. + b := &Access{ + Name: "Fatih", + LastAccessed: time.Now(), + Number: 12345, + } + validB := IsValid(b) + + fmt.Printf("%#v\n", validA) + fmt.Printf("%#v\n", validB) + // Output: + // false + // true +}