qiniu / goc

A Comprehensive Coverage Testing System for The Go Programming Language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

通过在main()方法的首行插入defer DoWhenClose()实现优雅重启

kiqi007 opened this issue · comments

commented

细一些的通用设计就看你们了,我自己改的一版可能仅使用我们的环境。

: main方法
func main(){defer gocDoClose()

}

:goc-cover文件
import goc "example.com/simple-project/goc-cover-agent-apis-auto-generated-11111-22222-package"
func gocDoClose() {
goc.Unregister()
}

:goc文件
func Unregister(){
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
http.syncCall(ctx, "req_config")
// 完成响应才退出,http这就可以通知最后一次采集了
}