MCPcopy Create free account
hub / github.com/cloudwan/gohan / PopulateDefaults

Method PopulateDefaults

schema/resource.go:177–199  ·  view source on GitHub ↗

PopulateDefaults Populates not provided data with defaults

()

Source from the content-addressed store, hash-verified

175
176//PopulateDefaults Populates not provided data with defaults
177func (resource *Resource) PopulateDefaults() error {
178 for _, property := range resource.Schema().Properties {
179 defaultValueMask := property.getDefaultMask()
180 resourceProperty, propertyFilled := resource.properties[property.ID]
181 if defaultValueMask != nil {
182 if property.Type == "object" {
183 defaultValueMaskMap := defaultValueMask.(map[string]interface{})
184 if propertyFilled && resourceProperty != nil {
185 resourceMap := resourceProperty.(map[string]interface{})
186 fillObjectDefaults(property, resourceMap, defaultValueMaskMap)
187 } else if defaultValueMaskMap != nil {
188 resource.properties[property.ID] = defaultValueMaskMap
189 }
190 } else {
191 if !propertyFilled {
192 resource.properties[property.ID] = defaultValueMask
193 }
194 }
195 }
196 }
197
198 return nil
199}

Callers 4

CreateResourceFunction · 0.80
resource_test.goFile · 0.80
CopyDBResourcesFunction · 0.80
GohanDbCreateFunction · 0.80

Calls 3

SchemaMethod · 0.95
fillObjectDefaultsFunction · 0.85
getDefaultMaskMethod · 0.80

Tested by

no test coverage detected