| 45 | } |
| 46 | |
| 47 | func ExampleSet_nested() { |
| 48 | type Retry struct { |
| 49 | Attempts int `default:"3"` |
| 50 | } |
| 51 | type Client struct { |
| 52 | // A struct is descended into with or without a tag, and a pointer needs one to be |
| 53 | // allocated at all. |
| 54 | Retry Retry |
| 55 | Fallback *Retry `default:"{}"` |
| 56 | Disabled *Retry |
| 57 | } |
| 58 | |
| 59 | var client Client |
| 60 | if err := defaults.Set(&client); err != nil { |
| 61 | panic(err) |
| 62 | } |
| 63 | |
| 64 | fmt.Println(client.Retry.Attempts) |
| 65 | fmt.Println(client.Fallback.Attempts) |
| 66 | fmt.Println(client.Disabled == nil) |
| 67 | // Output: |
| 68 | // 3 |
| 69 | // 3 |
| 70 | // true |
| 71 | } |
| 72 | |
| 73 | func ExampleSetter() { |
| 74 | var config Config |