proxyserver
This commit is contained in:
@@ -56,7 +56,7 @@ var (
|
||||
CodeUserIdNotFoundErr = &StatusResponse{5051, "user not found"} // 未找到用户
|
||||
CodePasswordErr = &StatusResponse{5052, "invalid password"} // 无效密码
|
||||
CodeEmailExistsErr = &StatusResponse{5053, "email exists"} // email存在
|
||||
CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email存在
|
||||
CodeEmailTimeShortErr = &StatusResponse{5053, "email with the time of resend is too short"} // email重发的时间太短
|
||||
CodeResetPasswordErr = &StatusResponse{5054, "reset password error"} // 无效密码
|
||||
|
||||
CodeSafeValueRangeErr = &StatusResponse{5040, "value not in range"} // 值不在范围内
|
||||
|
||||
@@ -15,9 +15,9 @@ type TimeLimit[T comparable] struct {
|
||||
dur time.Duration
|
||||
}
|
||||
|
||||
// NewTimelimit构造函数,接收限频的时间间隔
|
||||
// NewTimeLimit构造函数,接收限频的时间间隔
|
||||
// 并初始化内部字典和间隔字段
|
||||
func NewTimelimit[T comparable](dur time.Duration) *TimeLimit[T] {
|
||||
func NewTimeLimit[T comparable](dur time.Duration) *TimeLimit[T] {
|
||||
return &TimeLimit[T]{
|
||||
dict: make(map[T]struct{}),
|
||||
dur: dur,
|
||||
|
||||
@@ -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