mirror of
https://github.com/nikoksr/notify.git
synced 2024-11-24 08:22:18 +02:00
fmt/linter ran in correct order
This commit is contained in:
parent
d61e3712f5
commit
5dbd63751f
2
Makefile
2
Makefile
@ -27,7 +27,7 @@ test:
|
||||
|
||||
# gofumports and gci all go files
|
||||
fmt:
|
||||
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofumports -w "$$file"; done
|
||||
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofumpt -w "$$file"; done
|
||||
gci -w -local github.com/nikoksr/notify .
|
||||
.PHONY: fmt
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
package wechat
|
||||
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
"net/http"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
||||
// Config is the Service configuration.
|
||||
type Config struct {
|
||||
AppID string
|
||||
@ -37,7 +36,6 @@ type Service struct {
|
||||
|
||||
// New returns a new instance of a WeChat notification service.
|
||||
func New(cfg Config) *Service {
|
||||
|
||||
wc := wechat.NewWechat()
|
||||
wcCfg := &config.Config{
|
||||
AppID: cfg.AppID,
|
||||
@ -66,7 +64,6 @@ func (s *Service) WaitForOneOffVerification(
|
||||
addr string,
|
||||
devMode bool,
|
||||
callback func(r *http.Request, verified bool)) error {
|
||||
|
||||
srv := &http.Server{Addr: addr}
|
||||
verificationDone := &sync.WaitGroup{}
|
||||
verificationDone.Add(1)
|
||||
@ -79,11 +76,12 @@ func (s *Service) WaitForOneOffVerification(
|
||||
if callback != nil {
|
||||
callback(r, true)
|
||||
}
|
||||
w.Write([]byte(echoStr))
|
||||
_, _ = w.Write([]byte(echoStr))
|
||||
// verification done; dev mode
|
||||
verificationDone.Done()
|
||||
return
|
||||
} else {
|
||||
}
|
||||
|
||||
// perform signature check
|
||||
timestamp := query.Get("timestamp")
|
||||
nonce := query.Get("nonce")
|
||||
@ -93,12 +91,12 @@ func (s *Service) WaitForOneOffVerification(
|
||||
if callback != nil {
|
||||
callback(r, true)
|
||||
}
|
||||
w.Write([]byte(echoStr))
|
||||
_, _ = w.Write([]byte(echoStr))
|
||||
// verification done; prod mode
|
||||
verificationDone.Done()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// verification not done (keep waiting)
|
||||
if callback != nil {
|
||||
callback(r, false)
|
||||
@ -108,14 +106,16 @@ func (s *Service) WaitForOneOffVerification(
|
||||
var err error
|
||||
go func() {
|
||||
if innerErr := srv.ListenAndServe(); innerErr != http.ErrServerClosed {
|
||||
err = errors.Wrapf(innerErr, "failed to wait for verification at '%s'", addr)
|
||||
err = errors.Wrapf(innerErr, "failed to start verification listener '%s'", addr)
|
||||
}
|
||||
}()
|
||||
|
||||
// wait until verification is done and shutdown the server
|
||||
verificationDone.Wait()
|
||||
|
||||
srv.Shutdown(context.TODO())
|
||||
if innerErr := srv.Shutdown(context.TODO()); innerErr != nil {
|
||||
err = errors.Wrap(innerErr, "failed to shutdown verification listerer")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
@ -128,7 +128,6 @@ func (s *Service) AddReceivers(userIDs ...string) {
|
||||
|
||||
// Send takes a message subject and a message content and sends them to all previously set users.
|
||||
func (s *Service) Send(ctx context.Context, subject, content string) error {
|
||||
|
||||
for _, userID := range s.userIDs {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@ -143,4 +142,3 @@ func (s *Service) Send(ctx context.Context, subject, content string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,11 @@ package wechat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddReceivers(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user