mirror of
https://github.com/nikoksr/notify.git
synced 2024-12-02 08:51:50 +02:00
fix(lint): export types that are being returned by some methods
This commit is contained in:
parent
e1df17741c
commit
df3fb4c19d
@ -10,35 +10,35 @@ type sendToer interface {
|
|||||||
SendTo(subject, message, id, idType string) error
|
SendTo(subject, message, id, idType string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// receiverID encapsulates a receiver ID and its type in Lark.
|
// ReceiverID encapsulates a receiver ID and its type in Lark.
|
||||||
type receiverID struct {
|
type ReceiverID struct {
|
||||||
id string
|
id string
|
||||||
typ receiverIDType
|
typ receiverIDType
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenID specifies an ID as a Lark Open ID.
|
// OpenID specifies an ID as a Lark Open ID.
|
||||||
func OpenID(s string) *receiverID {
|
func OpenID(s string) *ReceiverID {
|
||||||
return &receiverID{s, openID}
|
return &ReceiverID{s, openID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserID specifies an ID as a Lark User ID.
|
// UserID specifies an ID as a Lark User ID.
|
||||||
func UserID(s string) *receiverID {
|
func UserID(s string) *ReceiverID {
|
||||||
return &receiverID{s, userID}
|
return &ReceiverID{s, userID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnionID specifies an ID as a Lark Union ID.
|
// UnionID specifies an ID as a Lark Union ID.
|
||||||
func UnionID(s string) *receiverID {
|
func UnionID(s string) *ReceiverID {
|
||||||
return &receiverID{s, unionID}
|
return &ReceiverID{s, unionID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Email specifies a receiver ID as an email.
|
// Email specifies a receiver ID as an email.
|
||||||
func Email(s string) *receiverID {
|
func Email(s string) *ReceiverID {
|
||||||
return &receiverID{s, email}
|
return &ReceiverID{s, email}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatID specifies an ID as a Lark Chat ID.
|
// ChatID specifies an ID as a Lark Chat ID.
|
||||||
func ChatID(s string) *receiverID {
|
func ChatID(s string) *ReceiverID {
|
||||||
return &receiverID{s, chatID}
|
return &ReceiverID{s, chatID}
|
||||||
}
|
}
|
||||||
|
|
||||||
// receiverIDType represents the different ID types implemented by Lark. This
|
// receiverIDType represents the different ID types implemented by Lark. This
|
||||||
|
@ -11,17 +11,18 @@ import (
|
|||||||
"github.com/nikoksr/notify"
|
"github.com/nikoksr/notify"
|
||||||
)
|
)
|
||||||
|
|
||||||
type customAppService struct {
|
// CustomAppService is a Lark notify service using a Lark custom app.
|
||||||
receiveIDs []*receiverID
|
type CustomAppService struct {
|
||||||
|
receiveIDs []*ReceiverID
|
||||||
cli sendToer
|
cli sendToer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile time check that larkCustomAppService implements notify.Notifer.
|
// Compile time check that larkCustomAppService implements notify.Notifer.
|
||||||
var _ notify.Notifier = &customAppService{}
|
var _ notify.Notifier = &CustomAppService{}
|
||||||
|
|
||||||
// NewCustomAppService returns a new instance of a Lark notify service using a
|
// NewCustomAppService returns a new instance of a Lark notify service using a
|
||||||
// Lark custom app.
|
// Lark custom app.
|
||||||
func NewCustomAppService(appID, appSecret string) *customAppService {
|
func NewCustomAppService(appID, appSecret string) *CustomAppService {
|
||||||
bot := lark.NewChatBot(appID, appSecret)
|
bot := lark.NewChatBot(appID, appSecret)
|
||||||
|
|
||||||
// We need to set the bot to use Lark's open.larksuite.com domain instead of
|
// We need to set the bot to use Lark's open.larksuite.com domain instead of
|
||||||
@ -36,8 +37,8 @@ func NewCustomAppService(appID, appSecret string) *customAppService {
|
|||||||
|
|
||||||
_ = bot.StartHeartbeat()
|
_ = bot.StartHeartbeat()
|
||||||
|
|
||||||
return &customAppService{
|
return &CustomAppService{
|
||||||
receiveIDs: make([]*receiverID, 0),
|
receiveIDs: make([]*ReceiverID, 0),
|
||||||
cli: &larkClientGoLarkChatBot{
|
cli: &larkClientGoLarkChatBot{
|
||||||
bot: bot,
|
bot: bot,
|
||||||
},
|
},
|
||||||
@ -55,13 +56,13 @@ func NewCustomAppService(appID, appSecret string) *customAppService {
|
|||||||
// lark.Email("xyz@example.com"),
|
// lark.Email("xyz@example.com"),
|
||||||
// lark.ChatID("oc_a0553eda9014c201e6969b478895c230"),
|
// lark.ChatID("oc_a0553eda9014c201e6969b478895c230"),
|
||||||
// )
|
// )
|
||||||
func (c *customAppService) AddReceivers(ids ...*receiverID) {
|
func (c *CustomAppService) AddReceivers(ids ...*ReceiverID) {
|
||||||
c.receiveIDs = append(c.receiveIDs, ids...)
|
c.receiveIDs = append(c.receiveIDs, ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send takes a message subject and a message body and sends them to all
|
// Send takes a message subject and a message body and sends them to all
|
||||||
// previously registered recipient IDs.
|
// previously registered recipient IDs.
|
||||||
func (c *customAppService) Send(ctx context.Context, subject, message string) error {
|
func (c *CustomAppService) Send(ctx context.Context, subject, message string) error {
|
||||||
for _, id := range c.receiveIDs {
|
for _, id := range c.receiveIDs {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
func TestAddReceivers(t *testing.T) {
|
func TestAddReceivers(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
xs := []*receiverID{
|
xs := []*ReceiverID{
|
||||||
OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
|
OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
|
||||||
UserID("8335aga2"),
|
UserID("8335aga2"),
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ func TestAddReceivers(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, svc.receiveIDs, xs)
|
assert.ElementsMatch(t, svc.receiveIDs, xs)
|
||||||
|
|
||||||
// Test if adding more receivers afterwards works.
|
// Test if adding more receivers afterwards works.
|
||||||
ys := []*receiverID{
|
ys := []*ReceiverID{
|
||||||
UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
|
UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
|
||||||
Email("xyz@example.com"),
|
Email("xyz@example.com"),
|
||||||
ChatID("oc_a0553eda9014c201e6969b478895c230"),
|
ChatID("oc_a0553eda9014c201e6969b478895c230"),
|
||||||
@ -36,7 +36,7 @@ func TestSendCustomApp(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
tests := []*receiverID{
|
tests := []*ReceiverID{
|
||||||
OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
|
OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
|
||||||
UserID("8335aga2"),
|
UserID("8335aga2"),
|
||||||
UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
|
UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
|
||||||
|
@ -9,20 +9,21 @@ import (
|
|||||||
"github.com/nikoksr/notify"
|
"github.com/nikoksr/notify"
|
||||||
)
|
)
|
||||||
|
|
||||||
type webhookService struct {
|
// WebhookService is a Notify service that uses a Lark webhook to send messages.
|
||||||
|
type WebhookService struct {
|
||||||
cli sender
|
cli sender
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile time check that larkCustomAppService implements notify.Notifer.
|
// Compile time check that larkCustomAppService implements notify.Notifer.
|
||||||
var _ notify.Notifier = &webhookService{}
|
var _ notify.Notifier = &WebhookService{}
|
||||||
|
|
||||||
// NewWebhookService returns a new instance of a Lark notify service using a
|
// NewWebhookService returns a new instance of a Lark notify service using a
|
||||||
// Lark group chat webhook. Note that this service does not take any
|
// Lark group chat webhook. Note that this service does not take any
|
||||||
// notification receivers because it can only push messages to the group chat
|
// notification receivers because it can only push messages to the group chat
|
||||||
// it belongs to.
|
// it belongs to.
|
||||||
func NewWebhookService(webhookURL string) *webhookService {
|
func NewWebhookService(webhookURL string) *WebhookService {
|
||||||
bot := lark.NewNotificationBot(webhookURL)
|
bot := lark.NewNotificationBot(webhookURL)
|
||||||
return &webhookService{
|
return &WebhookService{
|
||||||
cli: &larkClientGoLarkNotificationBot{
|
cli: &larkClientGoLarkNotificationBot{
|
||||||
bot: bot,
|
bot: bot,
|
||||||
},
|
},
|
||||||
@ -30,7 +31,7 @@ func NewWebhookService(webhookURL string) *webhookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send sends the message subject and body to the group chat.
|
// Send sends the message subject and body to the group chat.
|
||||||
func (w *webhookService) Send(ctx context.Context, subject, message string) error {
|
func (w *WebhookService) Send(ctx context.Context, subject, message string) error {
|
||||||
return w.cli.Send(subject, message)
|
return w.cli.Send(subject, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user