add option params

This commit is contained in:
zhuyasen
2022-11-06 23:58:44 +08:00
parent 2feee12878
commit 4076da8b0e
23 changed files with 110 additions and 1037 deletions

View File

@@ -1,44 +0,0 @@
package initial
import (
"context"
"time"
"github.com/zhufuyi/sponge/internal/config"
"github.com/zhufuyi/sponge/internal/model"
"github.com/zhufuyi/sponge/pkg/app"
"github.com/zhufuyi/sponge/pkg/tracer"
)
// RegisterClose 注册app需要释放的资源
func RegisterClose(servers []app.IServer) []app.Close {
var closes []app.Close
// 关闭服务
for _, s := range servers {
closes = append(closes, s.Stop)
}
// 关闭mysql
closes = append(closes, func() error {
return model.CloseMysql()
})
// 关闭redis
if config.Get().App.CacheType == "redis" {
closes = append(closes, func() error {
return model.CloseRedis()
})
}
// 关闭trace
if config.Get().App.EnableTracing {
closes = append(closes, func() error {
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) //nolint
return tracer.Close(ctx)
})
}
return closes
}