du8442 2018-12-19 03:56
浏览 84
已采纳

如何在golang中调试特定的api?

my wired situation is, the online service is working now, and everyday i can find a few 500 error reports like below:

2018-12-19 00:00:01     [ERROR] path[/vplay/getIdsInfo/?type=vlist&ids=31105228] err[runtime error: index out of range] stack[
goweb.(*RouterTab).ServeHTTP.func3.1:/home/tanxiaolong/golib/src/goweb/router.go:352
runtime.call64:/usr/local/go/src/runtime/asm_amd64.s:574
runtime.gopanic:/usr/local/go/src/runtime/panic.go:505
runtime.panicindex:/usr/local/go/src/runtime/panic.go:28
models.(*VplayModel).AssembleData:/home/tanxiaolong/golib/src/vplay/models/vplay.go:757
controllers.(*VplayController).GetIdsInfoAction:/home/tanxiaolong/golib/src/vplay/controllers/vplay.go:652
runtime.call32:/usr/local/go/src/runtime/asm_amd64.s:573
reflect.Value.call:/usr/local/go/src/reflect/value.go:447
reflect.Value.Call:/usr/local/go/src/reflect/value.go:308
goweb.(*RouterTab).ServeHTTP.func3:/home/tanxiaolong/golib/src/goweb/router.go:370
runtime.goexit:/usr/local/go/src/runtime/asm_amd64.s:2361]      (goweb/router.go:353)

i can find which api by log, but it returns 200 and correct response data if request it with the same query data as 500 requests by myself or wrk or ab.

i don't know how to debug this bug..

any suggestions on api debugging??

many thanks!

  • 写回答

1条回答 默认 最新

  • duanqi5114 2018-12-19 04:07
    关注

    When you're handling errors you can use:

    err.(*errors.Error).ErrorStack()

    to return the stacktrace. With that you can get the line in which your API in some cases gets an index out of range error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现