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

Method SetDefaults

example/main.go:43–47  ·  view source on GitHub ↗

SetDefaults implements defaults.Setter interface

()

Source from the content-addressed store, hash-verified

41
42// SetDefaults implements defaults.Setter interface
43func (s *OtherStruct) SetDefaults() {
44 if defaults.CanUpdate(s.Random) { // Check if it's a zero value (recommended)
45 s.Random = rand.Int() // Set a dynamic value
46 }
47}
48
49func main() {
50 obj := &Sample{}

Callers

nothing calls this directly

Calls 1

CanUpdateFunction · 0.92

Tested by

no test coverage detected