| 96 | } |
| 97 | |
| 98 | func ExampleSet_nested() { |
| 99 | type Retry struct { |
| 100 | Attempts int `default:"3"` |
| 101 | } |
| 102 | type Client struct { |
| 103 | // A struct is descended into with or without a tag, and a pointer needs one to be |
| 104 | // allocated at all. |
| 105 | Retry Retry |
| 106 | Fallback *Retry `default:"{}"` |
| 107 | Disabled *Retry |
| 108 | } |
| 109 | |
| 110 | var client Client |
| 111 | if err := defaults.Set(&client); err != nil { |
| 112 | panic(err) |
| 113 | } |
| 114 | |
| 115 | fmt.Println(client.Retry.Attempts) |
| 116 | fmt.Println(client.Fallback.Attempts) |
| 117 | fmt.Println(client.Disabled == nil) |
| 118 | // Output: |
| 119 | // 3 |
| 120 | // 3 |
| 121 | // true |
| 122 | } |
| 123 | |
| 124 | func ExampleSetter() { |
| 125 | var config Config |