mirror of
https://github.com/makayabou/asg-server.git
synced 2026-05-02 17:43:36 +02:00
48 lines
936 B
Go
48 lines
936 B
Go
package push
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/push/fcm"
|
|
"github.com/android-sms-gateway/server/internal/sms-gateway/modules/push/upstream"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var Module = fx.Module(
|
|
"push",
|
|
fx.Decorate(func(log *zap.Logger) *zap.Logger {
|
|
return log.Named("push")
|
|
}),
|
|
fx.Provide(
|
|
func(cfg Config, lc fx.Lifecycle) (c client, err error) {
|
|
if cfg.Mode == ModeFCM {
|
|
c, err = fcm.New(cfg.ClientOptions)
|
|
} else if cfg.Mode == ModeUpstream {
|
|
c, err = upstream.New(cfg.ClientOptions)
|
|
} else {
|
|
return nil, errors.New("invalid push mode")
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStart: func(ctx context.Context) error {
|
|
return c.Open(ctx)
|
|
},
|
|
OnStop: func(ctx context.Context) error {
|
|
return c.Close(ctx)
|
|
},
|
|
})
|
|
|
|
return c, nil
|
|
},
|
|
),
|
|
fx.Provide(
|
|
New,
|
|
),
|
|
)
|