github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/generator/templates/simpleschema/defaultsinit.gotmpl (about) 1 {{- if and .IsPrimitive .IsCustomFormatter (not (stringContains .Zero "(\"")) }} 2 if err := {{ varname .ID}}Default.UnmarshalText([]byte({{ printf "%q" .Default }})) ; err != nil { 3 msg := fmt.Sprintf("invalid default value for {{ varname .ID }}: %v",err) 4 panic(msg) // panics if the specification is invalid 5 } 6 {{- else if .IsArray }} 7 {{- if or ( and .Child.IsPrimitive .Child.IsCustomFormatter ) .Child.IsArray }} 8 if err := json.Unmarshal([]byte(`{{printf "%s" (json .Default)}}`), &{{ varname .ID }}Default); err != nil { 9 msg := fmt.Sprintf("invalid default value for {{ varname .ID }}: %v",err) 10 panic(msg) // panics if the specification is invalid 11 } 12 {{- else if and (not .Child.IsPrimitive) (not .Child.IsArray) }} {{/* shouldn't get there: guard */}} 13 if err := json.Unmarshal([]byte(`{{printf "%s" (json .Default)}}`), &{{ varname .ID }}Default); err != nil { 14 msg := fmt.Sprintf("invalid default value for {{ varname .ID }}: %v",err) 15 panic(msg) // panics if the specification is invalid 16 } 17 {{- end }} 18 {{- else if not .IsPrimitive }} {{/* shouldn't get there: guard (defaults to letting json figure out) */}} 19 if err := json.Unmarshal([]byte(`{{printf "%s" (json .Default)}}`), &{{ varname .ID }}Default); err != nil { 20 msg := fmt.Sprintf("invalid default value for {{ varname .ID }}: %v",err) 21 panic(msg) // panics if the specification is invalid 22 } 23 {{- end }}