代码拉取完成,页面将自动刷新
package sysExport
import (
"context"
"gitee.com/unitedrhino/core/service/syssvr/client/tenantmanage"
"gitee.com/unitedrhino/core/service/syssvr/pb/sys"
"gitee.com/unitedrhino/share/caches"
"gitee.com/unitedrhino/share/errors"
"gitee.com/unitedrhino/share/eventBus"
"github.com/parnurzeal/gorequest"
"net/http"
"time"
)
const (
CodeDmDeviceConn = "dmDeviceConn"
CodeDmDevicePropertyReport = "devicePropertyReport"
)
type Webhook struct {
*caches.Cache[sys.TenantOpenWebHook, string]
}
func NewTenantOpenWebhook(pm tenantmanage.TenantManage, fastEvent *eventBus.FastEvent) (*Webhook, error) {
c, err := NewTenantOpenWebhookCache(pm, fastEvent)
if err != nil {
return nil, err
}
return &Webhook{Cache: c}, nil
}
func (i *Webhook) Publish(ctx context.Context, code string, in any) error {
hook, err := i.GetData(ctx, GenWebhookCacheKey(ctx, code))
if err != nil {
if errors.Cmp(err, errors.NotFind) {
return nil
}
return err
}
req := gorequest.New().Retry(3, time.Second*2)
url := hook.Hosts[0] + hook.Uri
req.Post(url)
for k, v := range hook.Handler {
req.Set(k, v)
}
resp, body, errs := req.Type("json").Send(in).End()
if errs != nil {
return errors.System.AddDetail(errs)
}
if resp.StatusCode != http.StatusOK {
return errors.System.AddDetail(body)
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。