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.

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

报告相同问题?