发出中断信号后 调用的都是BaseStarter中的Stop函数

来源:8-8 golang中如何优雅的退出进程-notify hook starter编码实战

wlison

2020-08-27

写回答

3回答

枫荇

2020-09-08

是的,逻辑是监听到信号后,执行starter的Stop,由于golang的结构体包含原因,默认是使用”Starter
“接口,所以应该没问题的,注册的是哪个结构体就会调用哪个结构体的stop,如果包含了BaseStarter并且未覆盖,则会执行BaseStarter的stop.

这个同学可以使用时需要注意。


```

[2020-09-08.18:00:38.135805]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:base.PropsStarter

[2020-09-08.18:00:38.135969]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:base.DbxDatabaseStarter

[2020-09-08.18:00:38.136071]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:base.ValidatorStarter

[2020-09-08.18:00:38.136182]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:base.GoRPCStarter

[2020-09-08.18:00:38.136277]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:gorpc.GoRpcApiStarter

[2020-09-08.18:00:38.136411]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:jobs.RefundExpiredJobStarter

[2020-09-08.18:00:38.136510]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:infra.WebApiStarter

[2020-09-08.18:00:38.136602]  INFO imooc.com/resk/infra.(*HookStarter).Stop(infra/hook.go:43): stopping starter:base.IrisServerStarter

```

0
0

wlison

提问者

2020-08-27

应该是组合的问题 但是老师这个确实需要更改一下

0
0

wlison

提问者

2020-08-27

go 14.1

0
0

仿微信抢红包 Golang实战多版本抢红包系统

Golang红包系统单体版+并发版+分布式+微服务版,四大金装版、超值必修课

582 学习 · 159 问题

查看课程