You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
620 B
34 lines
620 B
5 years ago
|
package di
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
|
||
|
"{{.ModPrefix}}{{.Name}}/internal/service"
|
||
|
|
||
|
"github.com/bilibili/kratos/pkg/log"
|
||
|
"github.com/bilibili/kratos/pkg/net/rpc/warden"
|
||
|
)
|
||
|
|
||
|
//go:generate wire
|
||
|
type App struct {
|
||
|
svc *service.Service
|
||
|
grpc *warden.Server
|
||
|
}
|
||
|
|
||
|
func NewApp(svc *service.Service, g *warden.Server) (app *App, closeFunc func(), err error){
|
||
|
app = &App{
|
||
|
svc: svc,
|
||
|
grpc: g,
|
||
|
}
|
||
|
closeFunc = func() {
|
||
|
ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second)
|
||
|
if err := g.Shutdown(ctx); err != nil {
|
||
|
log.Error("grpcSrv.Shutdown error(%v)", err)
|
||
|
}
|
||
|
svc.Close()
|
||
|
cancel()
|
||
|
}
|
||
|
return
|
||
|
}
|