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

Function ExampleSet

example_test.go:75–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73}
74
75func ExampleSet() {
76 type Server struct {
77 Host string `default:"localhost"`
78 Port int `default:"8080"`
79 Timeout time.Duration `default:"30s"`
80 Tags []string `default:"[\"web\"]"`
81 Labels map[string]string `default:"{\"env\": \"dev\"}"`
82 }
83
84 var server Server
85 if err := defaults.Set(&server); err != nil {
86 panic(err)
87 }
88
89 fmt.Printf("%s:%d\n", server.Host, server.Port)
90 fmt.Println(server.Timeout)
91 fmt.Println(server.Tags, server.Labels)
92 // Output:
93 // localhost:8080
94 // 30s
95 // [web] map[env:dev]
96}
97
98func ExampleSet_nested() {
99 type Retry struct {

Callers

nothing calls this directly

Calls 1

SetFunction · 0.92

Tested by

no test coverage detected