我有下面的函数,它从终端接收命令,并根据输入打印一些东西.这似乎很简单,如果用户键入"添加",系统将打印一行,如果用户不键入任何内容,系统将打印其他内容.
每当用户输入add时,它都会工作.如果用户没有输入它抛出的任何内容
panic :运行时错误:GoLang中的索引超出范围
这是为什么呢?
func bootstrapCmd(c *commander.Command, inp []string) error {
if inp[0] == "add" {
fmt.Println("you typed add")
} else if inp[0] == "" {
fmt.Println("you didn't type add")
}
return nil
}