in codegen/header_propagate.go [88:135]
func typeSwitch(key, gotype string, field *compile.FieldSpec) []string {
var (
ret = []string{}
typeParse string
typeCast string
assignVal = "key"
)
switch gotype {
case "int8":
panic(fmt.Sprintf("type byte is note supported for field %q", field.Name))
case "bool":
typeParse = "strconv.ParseBool(key)"
assignVal = "v"
case "int16":
typeParse = "strconv.ParseInt(key, 10, 16)"
assignVal = "val"
typeCast = "val := int16(v)\n"
case "int32":
typeParse = "strconv.ParseInt(key, 10, 32)"
assignVal = "val"
typeCast = "val := int32(v)\n"
case "int64":
typeParse = "strconv.ParseInt(key, 10, 64)"
assignVal = "v"
case "float64":
typeParse = "strconv.ParseFloat(key, 64)"
assignVal = "v"
case "string":
default:
typeCast = "val := " + gotype + "(key)\n"
assignVal = "val"
}
if len(typeParse) > 0 {
ret = append(ret, fmt.Sprintf("if v, err := %s; err == nil {\n", typeParse))
}
if len(typeCast) > 0 {
ret = append(ret, typeCast)
}
if !field.Required {
ret = append(ret, fmt.Sprintf("in.%s = &%s\n", key, assignVal))
} else {
ret = append(ret, fmt.Sprintf("in.%s = %s\n", key, assignVal))
}
if len(typeParse) > 0 {
ret = append(ret, "}\n")
}
return ret
}