小编김종현*_*김종현的帖子

如何设置限制或只是注意函数参数的提示

如何设置参数限制如下?

// 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)

types arguments function go

-2
推荐指数
1
解决办法
64
查看次数

标签 统计

arguments ×1

function ×1

go ×1

types ×1