in tpgtools/property.go [271:323]
func buildGetter(p Property, rawGetter string) string {
switch p.Type.String() {
case SchemaTypeBool:
return fmt.Sprintf("dcl.Bool(%s.(bool))", rawGetter)
case SchemaTypeString:
if p.Type.IsEnum() {
return fmt.Sprintf("%s.%sEnumRef(%s.(string))", p.resource.Package(), p.ObjectType(), rawGetter)
}
if p.EnumBool {
return fmt.Sprintf("tpgdclresource.ExpandEnumBool(%s.(string))", rawGetter)
}
if p.Computed {
return fmt.Sprintf("dcl.StringOrNil(%s.(string))", rawGetter)
}
return fmt.Sprintf("dcl.String(%s.(string))", rawGetter)
case SchemaTypeFloat:
if p.Computed {
return fmt.Sprintf("dcl.Float64OrNil(%s.(float64))", rawGetter)
}
return fmt.Sprintf("dcl.Float64(%s.(float64))", rawGetter)
case SchemaTypeInt:
if p.Computed {
return fmt.Sprintf("dcl.Int64OrNil(int64(%s.(int)))", rawGetter)
}
return fmt.Sprintf("dcl.Int64(int64(%s.(int)))", rawGetter)
case SchemaTypeMap:
return fmt.Sprintf("tpgresource.CheckStringMap(%s)", rawGetter)
case SchemaTypeList, SchemaTypeSet:
if p.Type.IsEnumArray() {
return fmt.Sprintf("expand%s%sArray(%s)", p.resource.PathType(), p.PackagePath(), rawGetter)
}
if p.Type.IsComplexMap() {
return fmt.Sprintf("expand%s%sMap(%s)", p.resource.PathType(), p.PackagePath(), rawGetter)
}
if p.Type.typ.Items != nil && p.Type.typ.Items.Type == "string" {
return fmt.Sprintf("tpgdclresource.ExpandStringArray(%s)", rawGetter)
}
if p.Type.typ.Items != nil && p.Type.typ.Items.Type == "integer" {
return fmt.Sprintf("tpgdclresource.ExpandIntegerArray(%s)", rawGetter)
}
if p.Type.typ.Items != nil && len(p.Properties) > 0 {
return fmt.Sprintf("expand%s%sArray(%s)", p.resource.PathType(), p.PackagePath(), rawGetter)
}
}
if p.typ.Type == "object" {
return fmt.Sprintf("expand%s%s(%s)", p.resource.PathType(), p.PackagePath(), rawGetter)
}
return "<unknown>"
}