mirror of
https://github.com/nikoksr/notify.git
synced 2025-02-09 13:13:44 +02:00
fix: adjust code style
This commit is contained in:
parent
394a51da71
commit
720b9e73a3
@ -25,6 +25,7 @@ func New(channelSecret, channelAccessToken string) (*Line, error) {
|
|||||||
l := &Line{
|
l := &Line{
|
||||||
client: bot,
|
client: bot,
|
||||||
}
|
}
|
||||||
|
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,15 +41,14 @@ func (l *Line) Send(ctx context.Context, subject, message string) error {
|
|||||||
Text: subject + "\n" + message,
|
Text: subject + "\n" + message,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, destinationID := range l.receiverIDs {
|
for _, receiverID := range l.receiverIDs {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_, err := l.client.PushMessage(destinationID, lineMessage).WithContext(ctx).Do()
|
_, err := l.client.PushMessage(receiverID, lineMessage).WithContext(ctx).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to send message to line. destination id: '%s'", destinationID)
|
return errors.Wrapf(err, "failed to send message to LINE contact '%s'", receiverID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,14 @@ func main() {
|
|||||||
lineService.AddReceivers("userID1", "groupID1")
|
lineService.AddReceivers("userID1", "groupID1")
|
||||||
|
|
||||||
notifier := notify.New()
|
notifier := notify.New()
|
||||||
|
|
||||||
// Tell our notifier to use the line service. You can repeat the above process
|
// Tell our notifier to use the line service. You can repeat the above process
|
||||||
// for as many services as you like and just tell the notifier to use them.
|
// for as many services as you like and just tell the notifier to use them.
|
||||||
notifier.UseServices(lineService)
|
notifier.UseServices(lineService)
|
||||||
|
|
||||||
// Send a message
|
// Send a message
|
||||||
err := notifier.Send(context.Background(),
|
err := notifier.Send(
|
||||||
|
context.Background(),
|
||||||
"Welcome",
|
"Welcome",
|
||||||
"I am a bot written in Go!",
|
"I am a bot written in Go!",
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user