Situation
writing a code generator that checks fields of a struct and add validation functions using struct tags
Problem
Here I need to check if the type field is a custom type or not
ie,
Following are not custom types
int, []int,*int,[]Integer,map[string]PhoneNumber
But the following are custom type
Integer,PhoneNumber,*PhoneNumber
I think I can do it using functions like the following that looks for exact match and may add map,[] support
func isBuiltInType(typ string) bool {
switch typ {
case "bool", "byte", "complex128", "complex64", "error":
case "float32", "float64":
case "int", "int16", "int32", "int64", "int8":
case "rune", "string":
case "uint", "uint16", "uint32", "uint64", "uint8", "uintptr":
default:
return false
}
return true
}
But is there a better way to do it using parse.ParseExpr
etc