MCPcopy Create free account
hub / github.com/creasty/defaults / ExampleSet_nested

Function ExampleSet_nested

example_test.go:98–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96}
97
98func 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
124func ExampleSetter() {
125 var config Config

Callers

nothing calls this directly

Calls 1

SetFunction · 0.92

Tested by

no test coverage detected