语法糖:自动推断类型 和 无限放数组进来
func printArg(argList ...interface{}) string {
var (
//字节缓冲
outPutb bytes.Buffer
//参数类型
typeArg string
)
for _, arg := range argList {
//输出每个类型的值
str := fmt.Sprintf("%v", arg)
//判断每个参数的类型
switch arg.(type) {
case bool:
typeArg = "bool"
case types.Array:
typeArg = "array"
case string:
typeArg = "string"
case int:
typeArg = "int"
default:
typeArg = "unKnown"
}
outPutb.WriteString("值为:")
outPutb.WriteString(str)
outPutb.WriteString(" 类型为: ")
outPutb.WriteString(typeArg)
outPutb.WriteString("\n")
}
return outPutb.String()
}