1
0
mirror of https://github.com/nikoksr/notify.git synced 2025-02-07 13:08:12 +02:00

refactor(lint): apply golangci-lint recommendations

This commit is contained in:
Niko Köser 2022-08-04 17:13:17 +02:00
parent 82cc699565
commit a10eeb9247
No known key found for this signature in database
GPG Key ID: F3F28C118DAA6375
8 changed files with 59 additions and 58 deletions

View File

@ -51,8 +51,8 @@ type receiverIDType string
const (
openID receiverIDType = "open_id"
userID = "user_id"
unionID = "union_id"
email = "email"
chatID = "chat_id"
userID receiverIDType = "user_id"
unionID receiverIDType = "union_id"
email receiverIDType = "email"
chatID receiverIDType = "chat_id"
)

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/go-lark/lark"
"github.com/nikoksr/notify"
)
@ -32,7 +33,8 @@ func NewCustomAppService(appID, appSecret string) *customAppService {
bot.SetClient(&http.Client{
Timeout: 8 * time.Second,
})
bot.StartHeartbeat()
_ = bot.StartHeartbeat()
return &customAppService{
receiveIDs: make([]*receiverID, 0),
@ -43,16 +45,16 @@ func NewCustomAppService(appID, appSecret string) *customAppService {
}
// AddReceivers adds recipients to future notifications. There are five different
// types of receiver IDs availabe in Lark and they must be specified here. For
// types of receiver IDs available in Lark and they must be specified here. For
// example:
//
// larkService.AddReceivers(
// lark.OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
// lark.UserID("8335aga2"),
// lark.UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
// lark.Email("xyz@example.com"),
// lark.ChatID("oc_a0553eda9014c201e6969b478895c230"),
// )
// larkService.AddReceivers(
// lark.OpenID("ou_c99c5f35d542efc7ee492afe11af19ef"),
// lark.UserID("8335aga2"),
// lark.UnionID("on_cad4860e7af114fb4ff6c5d496d1dd76"),
// lark.Email("xyz@example.com"),
// lark.ChatID("oc_a0553eda9014c201e6969b478895c230"),
// )
func (c *customAppService) AddReceivers(ids ...*receiverID) {
c.receiveIDs = append(c.receiveIDs, ids...)
}

View File

@ -5,7 +5,6 @@ import (
"errors"
"testing"
"github.com/nikoksr/notify/service/lark/mocks"
"github.com/stretchr/testify/assert"
)
@ -47,7 +46,7 @@ func TestSendCustomApp(t *testing.T) {
// First, test for when the sender returns an error.
for _, tt := range tests {
mockSendToer := mocks.NewSendToer(t)
mockSendToer := NewSendToer(t)
mockSendToer.
On("SendTo", "subject", "message", tt.id, string(tt.typ)).
Return(errors.New(""))
@ -64,7 +63,7 @@ func TestSendCustomApp(t *testing.T) {
// Then test for when the sender does not return an error.
for _, tt := range tests {
mockSendToer := mocks.NewSendToer(t)
mockSendToer := NewSendToer(t)
mockSendToer.
On("SendTo", "subject", "message", tt.id, string(tt.typ)).
Return(nil)
@ -77,6 +76,5 @@ func TestSendCustomApp(t *testing.T) {
assert.Nil(err)
mockSendToer.AssertExpectations(t)
}
}

View File

@ -8,47 +8,46 @@ https://open.larksuite.com/document/home/develop-a-bot-in-5-minutes/create-an-ap
Usage:
package main
package main
import (
"context"
"log"
import (
"context"
"log"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/lark"
)
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/lark"
)
const (
webhookURL = "https://open.feishu.cn/open-apis/bot/v2/hook/xxx"
appId = "xxx"
appSecret = "xxx"
)
const (
webhookURL = "https://open.feishu.cn/open-apis/bot/v2/hook/xxx"
appId = "xxx"
appSecret = "xxx"
)
func main() {
// Two types of services are available depending on your requirements.
larkWebhookService := lark.NewWebhookService(webhookURL)
larkCustomAppService := lark.NewCustomAppService(appId, appSecret)
func main() {
// Two types of services are available depending on your requirements.
larkWebhookService := lark.NewWebhookService(webhookURL)
larkCustomAppService := lark.NewCustomAppService(appId, appSecret)
// Lark implements five types of receiver IDs. You'll need to specify the
// type using the respective helper functions when adding them as receivers
// for the custom app service.
larkCustomAppService.AddReceivers(
lark.OpenID("xxx"),
lark.UserID("xxx"),
lark.UnionID("xxx"),
lark.Email("xyz@example.com"),
lark.ChatID("xxx"),
)
// Lark implements five types of receiver IDs. You'll need to specify the
// type using the respective helper functions when adding them as receivers
// for the custom app service.
larkCustomAppService.AddReceivers(
lark.OpenID("xxx"),
lark.UserID("xxx"),
lark.UnionID("xxx"),
lark.Email("xyz@example.com"),
lark.ChatID("xxx"),
)
notifier := notify.New()
notifier.UseServices(larkWebhookService, larkCustomAppService)
notifier := notify.New()
notifier.UseServices(larkWebhookService, larkCustomAppService)
if err := notifier.Send(context.Background(), "subject", "message"); err != nil {
log.Fatalf("notifier.Send() failed: %s", err.Error())
}
if err := notifier.Send(context.Background(), "subject", "message"); err != nil {
log.Fatalf("notifier.Send() failed: %s", err.Error())
}
log.Println("notification sent")
}
log.Println("notification sent")
}
*/
package lark

View File

@ -1,8 +1,8 @@
// Code generated by mockery v2.12.3. DO NOT EDIT.
package mocks
package lark
import mock "github.com/stretchr/testify/mock"
import "github.com/stretchr/testify/mock"
// SendToer is an autogenerated mock type for the sendToer type
type SendToer struct {

View File

@ -1,8 +1,8 @@
// Code generated by mockery v2.12.3. DO NOT EDIT.
package mocks
package lark
import mock "github.com/stretchr/testify/mock"
import "github.com/stretchr/testify/mock"
// Sender is an autogenerated mock type for the sender type
type Sender struct {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/go-lark/lark"
"github.com/nikoksr/notify"
)

View File

@ -5,17 +5,18 @@ import (
"errors"
"testing"
"github.com/nikoksr/notify/service/lark/mocks"
"github.com/stretchr/testify/assert"
)
func TestSendWebhook(t *testing.T) {
t.Parallel()
assert := assert.New(t)
ctx := context.Background()
// First, test for when the sender returns an error.
{
mockSender := mocks.NewSender(t)
mockSender := NewSender(t)
mockSender.
On("Send", "subject", "message").
Return(errors.New(""))
@ -29,7 +30,7 @@ func TestSendWebhook(t *testing.T) {
// Then test for when the sender does not return an error.
{
mockSender := mocks.NewSender(t)
mockSender := NewSender(t)
mockSender.
On("Send", "subject", "message").
Return(nil)