proxyserver
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package wevent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/474420502/requests"
|
||||
)
|
||||
|
||||
// 和前端交流的事件机制
|
||||
@@ -22,6 +25,34 @@ type WebsocketEvent struct {
|
||||
Data any `json:"data"` // 关注的数据
|
||||
}
|
||||
|
||||
func CommonNotify(WebsocketAddr, wid string, event *WebsocketEvent) error {
|
||||
|
||||
reqWebsocketAddr := fmt.Sprintf("%s/api/websocket/common_notify", WebsocketAddr)
|
||||
tp := requests.Post(reqWebsocketAddr)
|
||||
tp.SetBodyJson(requests.M{
|
||||
"wid": wid,
|
||||
"data": event,
|
||||
})
|
||||
|
||||
wresp, err := tp.Execute()
|
||||
if err != nil {
|
||||
// logx.Error(err, token.TraceId)
|
||||
return err
|
||||
}
|
||||
|
||||
result := wresp.Json()
|
||||
|
||||
if !result.Get("code").Exists() {
|
||||
return fmt.Errorf("send %s is error", reqWebsocketAddr)
|
||||
}
|
||||
|
||||
if result.Get("code").Int() != 200 {
|
||||
return fmt.Errorf("%s", result.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewWebsocketEvent 创建一个Websocket事件
|
||||
func NewWebsocketEvent(etype EventType, TraceId string) *WebsocketEvent {
|
||||
return &WebsocketEvent{
|
||||
|
||||
Reference in New Issue
Block a user