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

Function ExampleSet_nested

example_test.go:47–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45}
46
47func 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
73func ExampleSetter() {
74 var config Config

Callers

nothing calls this directly

Calls 1

SetFunction · 0.92

Tested by

no test coverage detected