proxyserver

This commit is contained in:
eson
2023-10-09 14:41:57 +08:00
parent 12a6e95a11
commit 9fdc5b4dbf
10 changed files with 94 additions and 61 deletions

View File

@@ -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"} // 值不在范围内

View File

@@ -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,

View File

@@ -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{