如何设置参数限制如下?
// 1.
func ChooseColor(color string:"black|white" ) {
fmt.Println(color)
}
ChooseColor("white") // console "white"
ChooseColor("yellow") // console panic
Run Code Online (Sandbox Code Playgroud)
如果你觉得菜鸟不能理解上面的解决方案,那么交替看下面
// 2.
/**
* arg: "black|white"
*
*/
func ChooseColor(color string) {
fmt.Println(color)
}
ChooseColor( ) // IDE can notice "color: black || white"
Run Code Online (Sandbox Code Playgroud)
请帮帮我(TT)