Skip to content

Commit

Permalink
style(hook): 调整命名结构
Browse files Browse the repository at this point in the history
  • Loading branch information
aide-cloud committed Apr 26, 2024
1 parent c3db760 commit be1f03a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type HookNotifyMsg struct {
}

type HookNotify interface {
// Alarm 告警通知接口
Alarm(ctx context.Context, url string, msg *HookNotifyMsg) error
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"net/url"
"time"

"github.com/go-kratos/kratos/v2/log"
"github.com/aide-family/moon/pkg/httpx"
"github.com/go-kratos/kratos/v2/log"
)

var _ HookNotify = (*dingNotify)(nil)
Expand All @@ -36,9 +36,12 @@ func (l *dingNotify) Alarm(ctx context.Context, url string, msg *HookNotifyMsg)
})
reqUrl := fmt.Sprintf("%s&%s", url, params)
response, err := httpx.NewHttpX().POSTWithContext(ctx, reqUrl, []byte(msg.Content))
if err != nil {
return err
}
body := response.Body
resBytes, err := io.ReadAll(body)
defer body.Close()
resBytes, err := io.ReadAll(body)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strconv"
"time"

"github.com/go-kratos/kratos/v2/log"
"github.com/aide-family/moon/pkg/httpx"
"github.com/go-kratos/kratos/v2/log"
)

var _ HookNotify = (*feishuNotify)(nil)
Expand All @@ -37,9 +37,12 @@ func (l *feishuNotify) Alarm(ctx context.Context, url string, msg *HookNotifyMsg
notifyMsg["sign"] = GenSign(msg.Secret, timeNow.Unix())
notifyMsgBytes, _ := json.Marshal(notifyMsg)
response, err := httpx.NewHttpX().POSTWithContext(ctx, url, notifyMsgBytes)
if err != nil {
return err
}
body := response.Body
resBytes, err := io.ReadAll(body)
defer body.Close()
resBytes, err := io.ReadAll(body)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"io"

"github.com/go-kratos/kratos/v2/log"
"github.com/aide-family/moon/pkg/httpx"
"github.com/go-kratos/kratos/v2/log"
)

var _ HookNotify = (*otherNotify)(nil)
Expand All @@ -14,9 +14,12 @@ type otherNotify struct{}

func (l *otherNotify) Alarm(ctx context.Context, url string, msg *HookNotifyMsg) error {
response, err := httpx.NewHttpX().POSTWithContext(ctx, url, msg.AlarmInfo.Bytes())
if err != nil {
return err
}
body := response.Body
resBytes, err := io.ReadAll(body)
defer body.Close()
resBytes, err := io.ReadAll(body)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"io"

"github.com/go-kratos/kratos/v2/log"
"github.com/aide-family/moon/pkg/httpx"
"github.com/go-kratos/kratos/v2/log"
)

var _ HookNotify = (*wechatNotify)(nil)
Expand Down Expand Up @@ -40,9 +40,12 @@ func (l *WechatHookResp) Error() string {

func (l *wechatNotify) Alarm(ctx context.Context, url string, msg *HookNotifyMsg) error {
response, err := httpx.NewHttpX().POSTWithContext(ctx, url, []byte(msg.Content))
if err != nil {
return err
}
body := response.Body
resBytes, err := io.ReadAll(body)
defer body.Close()
resBytes, err := io.ReadAll(body)
if err != nil {
return err
}
Expand Down

0 comments on commit be1f03a

Please sign in to comment.