我想使用标签来最小化错误部分,如下所示:
package main
import (
"fmt"
consul "github.com/hashicorp/consul/api"
"os"
)
func main(){
client,err := consul.NewClient(consul.DefaultConfig())
if err != nil {
goto Err
}
agent := client.Agent()
checkReg := agent.AgentCheckRegistration{
ID: "test-check",
Name: "test-check",
Notes: "some test check",
}
if err = agent.CheckRegister(checkReg); err !=nil{
goto Err
}
Err:
fmt.Println(err)
os.Exit(2)
}
所以我可以有一个地方把所有的错误处理放在一个地方,但似乎不起作用
./agent.CheckRegister.go:10:8: goto Err jumps over declaration of checkReg at
./agent.CheckRegister.go:13:19: agent.AgentCheckRegistration undefined (type *api.Agent has no field or method AgentCheckRegistration)
有没有办法使用goto来使它工作?
Smart猫小萌
相关分类