用一些错误消息中止我的API服务的方法是什么?
调用我的服务的链接:
http://creative.test.spoti.io/api/getVastPlayer?add=
{"Json":Json}&host=api0.spoti.io&domain=domain&userAgent=userAgent&mobile=true
要调用我的服务,客户端需要发送一个 Json 和一些参数。
我想测试我得到的参数是否正确,如果不正确,我想发送一条错误消息。
响应应该是一个 Json 代码 {"Result":"Result","Error":"error message"}
我试过了log.fatal,os.Exit(1)他们停止了服务,而不仅仅是呼叫请求。panic中止呼叫,但它阻止我发送http.ResponseWriter错误消息。
我读了一些关于恐慌、延迟、恢复的内容,但我真的不知道如何使用它们来解决这个问题。
return 作品:
mobile :=query.Get("mobile")
if mobile=="mobile" {
str:=`{"Resultt":"","Error":"No valide Var"}`
fmt.Fprint(w, str)
fmt.Println("No successfull Operation!!")
return}
但是我只能在 main 函数中使用它,因为在其他函数中它只退出 func 而不是调用者函数(请求)。
江户川乱折腾
相关分类