if fileFormat == "csv" || fileFormat == "xlsx" || fileFormat == "xls" {
}
提示能简写,但是不知道怎么写
if fileFormat == "csv" || fileFormat == "xlsx" || fileFormat == "xls" {
}
提示能简写,但是不知道怎么写
var fileTypes = map[string]bool{
"cvs",
"xlsx",
"txt",
}
if _,ok := fileTypes[val] ; ok {
// 存在
} else {
// 不存在
}
你写个InArray数组
fileFormatList :=[]string{"csv","xlsx","xls"}
if InArray(fileFormat,fileFormatList){
...
}
7 回答5.3k 阅读
6 回答6.8k 阅读✓ 已解决
4 回答2.3k 阅读
1 回答3.4k 阅读
2 回答885 阅读✓ 已解决
2 回答2.2k 阅读
1 回答2.1k 阅读
不在于怎么去简化,而是怎么去封装。比如可以写一个函数:
GO没有太多语法糖,写代码都需要自己去提炼一些常用的工具函数