Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

golang if 多个条件怎么简写

if fileFormat == "csv" || fileFormat == "xlsx" || fileFormat == "xls" {

    }

提示能简写,但是不知道怎么写


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

不在于怎么去简化,而是怎么去封装。比如可以写一个函数:

func InArray(value string, array []string) bool {
    // ...
    return true
}

GO没有太多语法糖,写代码都需要自己去提炼一些常用的工具函数


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...