feat(app): update

This commit is contained in:
Yangtao
2025-11-19 11:30:26 +08:00
parent 337fbce076
commit 1eac66d7fd

46
pkg/starter/starter.go Normal file
View File

@ -0,0 +1,46 @@
package starter
import (
"fmt"
"os"
"os/signal"
"syscall"
"gitea.ddegame.cn/open/servicebase/pkg/log"
)
type IStarter interface {
Init() error
}
type Starter struct {
instanceList []IStarter
instanceCount int
errs []error
}
func NewStarter() *Starter {
return &Starter{}
}
func (s *Starter) With(instance IStarter) *Starter {
s.instanceList = append(s.instanceList, instance)
return s
}
func (s *Starter) Run() {
for _, instance := range s.instanceList {
if err := instance.Init(); err != nil {
s.errs = append(s.errs, err)
}
}
if len(s.errs) > 0 {
panic(fmt.Sprintf("some errors: %v", s.errs))
}
log.Info("service all up")
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
sig := <-ch
log.InfoF("api server Got %s signal. Aborting...\n", sig)
os.Exit(1)
}