优化服务监控定时器,移除notify功能包

This commit is contained in:
孟帅
2023-08-07 17:58:24 +08:00
parent 3df5236623
commit 90d09deeff
88 changed files with 415 additions and 723 deletions

View File

@@ -1,3 +1,8 @@
// Package addons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package addons
import (

View File

@@ -1,3 +1,8 @@
// Package addons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package addons
const (

View File

@@ -1,3 +1,8 @@
// Package file
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package file
import (

View File

@@ -1,3 +1,8 @@
// Package contexts
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package contexts
import (

View File

@@ -116,6 +116,33 @@ func (l *Lock) Unlock(ctx context.Context) error {
return err
}
func (l *Lock) LockFunc(ctx context.Context, f func()) error {
if err := l.Lock(ctx); err != nil {
return err
}
defer func() {
_ = l.Unlock(ctx)
}()
f()
return nil
}
// TryLockFunc tries locking the mutex for writing with given callback function `f`.
// it returns true immediately if success, or if there's a lock on the mutex,
// it returns error immediately.
//
// It releases the lock after `f` is executed.
func (l *Lock) TryLockFunc(ctx context.Context, f func()) error {
err := l.TryLock(ctx)
if err != nil {
defer func() {
_ = l.Unlock(ctx)
}()
f()
}
return err
}
// startWatchDog 看门狗
func (l *Lock) startWatchDog() {
resetTTLInterval := l.ttl / 3

View File

@@ -32,9 +32,6 @@ func SubscribeMap(channels map[string]SubHandler) (err error) {
return
}
subscribes.mutex.Lock()
defer subscribes.mutex.Unlock()
for channel, hr := range channels {
if err = Subscribe(channel, hr); err != nil {
return

View File

@@ -1,79 +0,0 @@
package feishu
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"strconv"
"time"
"hotgo/internal/library/notify/feishu/internal/security"
)
const feishuAPI = "https://open.feishu.cn/open-apis/bot/v2/hook/"
// Client feishu client
type Client struct {
AccessToken string
Secret string
}
// NewClient new client
func NewClient(accessToken, secret string) *Client {
return &Client{
AccessToken: accessToken,
Secret: secret,
}
}
// Response response struct
type Response struct {
Code int64 `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
Extra interface{} `json:"Extra"`
StatusCode int64 `json:"StatusCode"`
StatusMessage string `json:"StatusMessage"`
}
// Send send message
func (d *Client) Send(message Message) (string, *Response, error) {
res := &Response{}
if len(d.AccessToken) < 1 {
return "", res, fmt.Errorf("accessToken is empty")
}
timestamp := time.Now().Unix()
sign, err := security.GenSign(d.Secret, timestamp)
if err != nil {
return "", res, err
}
body := message.Body()
body["timestamp"] = strconv.FormatInt(timestamp, 10)
body["sign"] = sign
reqBytes, err := json.Marshal(body)
if err != nil {
return "", res, err
}
var (
result *Response
URL = fmt.Sprintf("%v%v", feishuAPI, d.AccessToken)
reqString = string(reqBytes)
)
g.Client().
Retry(3, time.Second).
SetHeader("Accept", "application/json").
SetHeader("Content-Type", "application/json").
PostVar(gctx.New(), URL, &result)
if result.Code != 0 {
return reqString, result, fmt.Errorf("send message to feishu error = %s", result.Msg)
}
return reqString, result, nil
}

View File

@@ -1,24 +0,0 @@
package feishu
type ImageMessage struct {
MsgType MsgType `json:"msg_type"`
Content ImageContent `json:"content"`
}
type ImageContent struct {
ImageKey string `json:"image_key"`
}
func (m *ImageMessage) Body() map[string]interface{} {
m.MsgType = MsgTypeImage
return structToMap(m)
}
func NewImageMessage() *ImageMessage {
return &ImageMessage{}
}
func (m *ImageMessage) SetImageKey(key string) *ImageMessage {
m.Content.ImageKey = key
return m
}

View File

@@ -1,21 +0,0 @@
package feishu
type InteractiveMessage struct {
MsgType MsgType `json:"msg_type"`
Card string `json:"card"`
}
func (m *InteractiveMessage) Body() map[string]interface{} {
m.MsgType = MsgTypeInteractive
return structToMap(m)
}
func NewInteractiveMessage() *InteractiveMessage {
return &InteractiveMessage{}
}
// SetCard set card with cardbuilder https://open.feishu.cn/tool/cardbuilder?from=custom_bot_doc
func (m *InteractiveMessage) SetCard(card string) *InteractiveMessage {
m.Card = card
return m
}

View File

@@ -1,21 +0,0 @@
package security
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
// GenSign generate sign
func GenSign(secret string, timestamp int64) (string, error) {
stringToSign := fmt.Sprintf("%v", timestamp) + "\n" + secret
var data []byte
h := hmac.New(sha256.New, []byte(stringToSign))
_, err := h.Write(data)
if err != nil {
return "", err
}
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
return signature, nil
}

View File

@@ -1,66 +0,0 @@
package feishu
import (
"reflect"
"strings"
)
type MsgType string
// MsgType
const (
MsgTypeText MsgType = "text"
MsgTypePost MsgType = "post"
MsgTypeImage MsgType = "image"
MsgTypeShareChat MsgType = "share_chat"
MsgTypeInteractive MsgType = "interactive"
)
// Message interface
type Message interface {
Body() map[string]interface{}
}
func structToMap(item interface{}) map[string]interface{} {
res := map[string]interface{}{}
if item == nil {
return res
}
v := reflect.TypeOf(item)
reflectValue := reflect.ValueOf(item)
reflectValue = reflect.Indirect(reflectValue)
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
for i := 0; i < v.NumField(); i++ {
tag := v.Field(i).Tag.Get("json")
// remove omitEmpty
omitEmpty := false
if strings.HasSuffix(tag, "omitempty") {
omitEmpty = true
idx := strings.Index(tag, ",")
if idx > 0 {
tag = tag[:idx]
} else {
tag = ""
}
}
field := reflectValue.Field(i).Interface()
if tag != "" && tag != "-" {
if omitEmpty && reflectValue.Field(i).IsZero() {
continue
}
if v.Field(i).Type.Kind() == reflect.Struct {
res[tag] = structToMap(field)
} else {
res[tag] = field
}
}
}
return res
}

View File

@@ -1,170 +0,0 @@
package feishu
import (
"encoding/json"
"log"
)
type PostMessage struct {
MsgType MsgType `json:"msg_type"`
Content PostContent `json:"content"`
}
func NewPostMessage() *PostMessage {
return &PostMessage{}
}
func (m *PostMessage) Body() map[string]interface{} {
m.MsgType = MsgTypePost
return structToMap(m)
}
func (m *PostMessage) SetZH(u PostUnit) *PostMessage {
m.Content.Post.ZH = u
return m
}
func (m *PostMessage) SetZHTitle(t string) *PostMessage {
m.Content.Post.ZH.Title = t
return m
}
func (m *PostMessage) AppendZHContent(i []PostItem) *PostMessage {
m.Content.Post.ZH.Content = append(m.Content.Post.ZH.Content, i)
return m
}
func (m *PostMessage) SetJA(u PostUnit) *PostMessage {
m.Content.Post.JA = u
return m
}
func (m *PostMessage) SetJATitle(t string) *PostMessage {
m.Content.Post.JA.Title = t
return m
}
func (m *PostMessage) AppendJAContent(i []PostItem) *PostMessage {
m.Content.Post.JA.Content = append(m.Content.Post.JA.Content, i)
return m
}
func (m *PostMessage) SetEN(u PostUnit) *PostMessage {
m.Content.Post.EN = u
return m
}
func (m *PostMessage) SetENTitle(t string) *PostMessage {
m.Content.Post.EN.Title = t
return m
}
func (m *PostMessage) AppendENContent(i []PostItem) *PostMessage {
m.Content.Post.EN.Content = append(m.Content.Post.EN.Content, i)
return m
}
type PostContent struct {
Post PostBody `json:"post"`
}
type PostBody struct {
ZH PostUnit `json:"zh_cn,omitempty"`
JA PostUnit `json:"ja_jp,omitempty"`
EN PostUnit `json:"en_us,omitempty"`
}
type PostUnit struct {
Title string `json:"title,omitempty"`
Content [][]PostItem `json:"content"`
}
type PostItem interface{}
type Text struct {
Tag string `json:"tag"`
Text string `json:"text"`
UnEscape bool `json:"un_escape,omitempty"`
}
func NewText(text string) Text {
t := Text{
Tag: "text",
Text: text,
}
return t
}
type A struct {
Tag string `json:"tag"`
Text string `json:"text"`
Href string `json:"href"`
UnEscape bool `json:"un_escape,omitempty"`
}
func NewA(text, href string) A {
t := A{
Tag: "a",
Text: text,
Href: href,
}
return t
}
type AT struct {
Tag string `json:"tag"`
UserID string `json:"user_id"`
}
func NewAT(userID string) AT {
t := AT{
Tag: "at",
UserID: userID,
}
return t
}
type Image struct {
Tag string `json:"tag"`
ImageKey string `json:"image_key"`
Height int `json:"height"`
Width int `json:"width"`
}
func NewImage(imageKey string, height, width int) Image {
t := Image{
Tag: "image",
ImageKey: imageKey,
Height: height,
Width: width,
}
return t
}
type PostCMDMessage struct {
MsgType MsgType `json:"msg_type"`
Content PostCMDContent `json:"content"`
}
func (m *PostCMDMessage) Body() map[string]interface{} {
m.MsgType = MsgTypePost
return structToMap(m)
}
type PostCMDContent struct {
Post map[string]interface{} `json:"post"`
}
func NewPostCMDMessage() *PostCMDMessage {
return &PostCMDMessage{}
}
func (m *PostCMDMessage) SetPost(post string) *PostCMDMessage {
var result map[string]interface{}
err := json.Unmarshal([]byte(post), &result)
if err != nil {
log.Print("SetPost err: ", err)
}
m.Content.Post = result
return m
}

View File

@@ -1,24 +0,0 @@
package feishu
type ShareChatMessage struct {
MsgType MsgType `json:"msg_type"`
Content ShareChatContent `json:"content"`
}
type ShareChatContent struct {
ShareChatID string `json:"share_chat_id"`
}
func (m *ShareChatMessage) Body() map[string]interface{} {
m.MsgType = MsgTypeShareChat
return structToMap(m)
}
func NewShareChatMessage() *ShareChatMessage {
return &ShareChatMessage{}
}
func (m *ShareChatMessage) SetShareChatID(id string) *ShareChatMessage {
m.Content.ShareChatID = id
return m
}

View File

@@ -1,24 +0,0 @@
package feishu
type TextMessage struct {
MsgType MsgType `json:"msg_type"`
Content Content `json:"content"`
}
type Content struct {
Text string `json:"text"`
}
func (m *TextMessage) Body() map[string]interface{} {
m.MsgType = MsgTypeText
return structToMap(m)
}
func NewTextMessage() *TextMessage {
return &TextMessage{}
}
func (m *TextMessage) SetText(text string) *TextMessage {
m.Content.Text = text
return m
}

View File

@@ -1,3 +1,8 @@
// Package alipay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package alipay
import (

View File

@@ -1,3 +1,8 @@
// Package alipay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package alipay
import "github.com/gogf/gf/v2/os/gtime"

View File

@@ -1,3 +1,8 @@
// Package payment
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package payment
import "hotgo/internal/model"

View File

@@ -1,3 +1,8 @@
// Package payment
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package payment
import (

View File

@@ -1,3 +1,8 @@
// Package payment
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package payment
import (

View File

@@ -1,3 +1,8 @@
// Package qqpay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package qqpay
import (

View File

@@ -1,3 +1,8 @@
// Package qqpay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package qqpay
// NotifyRequest QQ支付异步通知参数

View File

@@ -1,3 +1,8 @@
// Package wxpay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package wxpay
import (

View File

@@ -1 +1,6 @@
// Package wxpay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package wxpay

View File

@@ -1,3 +1,8 @@
// Package queue
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queue
import (

View File

@@ -1,3 +1,8 @@
// Package queue
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queue
import (

View File

@@ -1,3 +1,8 @@
// Package disk
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package disk
import (

View File

@@ -1,3 +1,8 @@
// Package disk
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package disk
import (

View File

@@ -1,3 +1,8 @@
// Package disk
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package disk
import (

View File

@@ -1,3 +1,8 @@
// Package queue
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queue
import (

View File

@@ -1,3 +1,8 @@
// Package queue
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queue
import (

View File

@@ -1,3 +1,8 @@
// Package sms
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sms
import (

View File

@@ -1,3 +1,8 @@
// Package sms
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sms
import (

View File

@@ -1,3 +1,8 @@
// Package sms
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sms
import (

View File

@@ -1,3 +1,8 @@
// Package sms
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sms
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
// FileMeta 文件元数据

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package storager
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package storager
import (

View File

@@ -1,3 +1,8 @@
// Package token
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package token
import (

View File

@@ -1,3 +1,8 @@
// Package wechat
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package wechat
import (

View File

@@ -1,3 +1,8 @@
// Package wechat
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package wechat
import "hotgo/internal/model"

View File

@@ -1,3 +1,8 @@
// Package wechat
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package wechat
import (