-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrates an APNs pusher into data service
If the necessary configuration isn't found, then push notifications will instead be logged. BACK-2554
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package push | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/tidepool-org/platform/devicetokens" | ||
"github.com/tidepool-org/platform/log" | ||
logjson "github.com/tidepool-org/platform/log/json" | ||
lognull "github.com/tidepool-org/platform/log/null" | ||
) | ||
|
||
// LogPusher logs notifications instead of sending push notifications. | ||
// | ||
// Useful for dev or testing situations. | ||
type LogPusher struct { | ||
log.Logger | ||
} | ||
|
||
// NewLogPusher uses a [log.Logger] instead of pushing via APNs. | ||
func NewLogPusher(l log.Logger) *LogPusher { | ||
if l == nil { | ||
var err error | ||
l, err = logjson.NewLogger(os.Stderr, log.DefaultLevelRanks(), log.DefaultLevel()) | ||
if err != nil { | ||
l = lognull.NewLogger() | ||
} | ||
} | ||
return &LogPusher{Logger: l} | ||
} | ||
|
||
// Push implements [service.Pusher]. | ||
func (p *LogPusher) Push(ctx context.Context, deviceToken *devicetokens.DeviceToken, note *Notification) error { | ||
p.Logger.WithFields(log.Fields{ | ||
"deviceToken": deviceToken, | ||
"note": note, | ||
}).Info("logging push notification") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters