mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
37 lines
764 B
Go
37 lines
764 B
Go
package online
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/android-sms-gateway/server/internal/sms-gateway/cache"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func Module() fx.Option {
|
|
return fx.Module(
|
|
"online",
|
|
fx.Decorate(func(log *zap.Logger) *zap.Logger {
|
|
return log.Named("online")
|
|
}),
|
|
fx.Provide(func(factory cache.Factory) (cache.Cache, error) {
|
|
return factory.New("online")
|
|
}, fx.Private),
|
|
fx.Provide(newMetrics),
|
|
fx.Provide(New),
|
|
fx.Invoke(func(lc fx.Lifecycle, svc Service) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
lc.Append(fx.Hook{
|
|
OnStart: func(_ context.Context) error {
|
|
go svc.Run(ctx)
|
|
return nil
|
|
},
|
|
OnStop: func(_ context.Context) error {
|
|
cancel()
|
|
return nil
|
|
},
|
|
})
|
|
}),
|
|
)
|
|
}
|