网关重启时恢复权限与分配数据
This commit is contained in:
@@ -8,3 +8,8 @@ type Permit struct {
|
||||
Username *string `json:"username"`
|
||||
Password *string `json:"password"`
|
||||
}
|
||||
|
||||
type PermitDef struct {
|
||||
Id int32 `json:"id"`
|
||||
Permit
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func processCtrlConn(_ctx context.Context, conn net.Conn) (err error) {
|
||||
|
||||
// 读取命令
|
||||
cmd, err := reader.ReadByte()
|
||||
if errors.Is(err, syscall.WSAECONNRESET) {
|
||||
if errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.WSAECONNRESET) {
|
||||
slog.Debug("节点重置了控制通道连接(WSAECONNRESET)")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ func Online(name string) (err error) {
|
||||
}
|
||||
|
||||
var body struct {
|
||||
Id int32 `json:"id"`
|
||||
Secret string `json:"secret"`
|
||||
Id int32 `json:"id"`
|
||||
Secret string `json:"secret"`
|
||||
Permits []core.PermitDef `json:"permits"`
|
||||
}
|
||||
err = json.Unmarshal([]byte(resp), &body)
|
||||
if err != nil {
|
||||
@@ -33,6 +34,9 @@ func Online(name string) (err error) {
|
||||
|
||||
app.Id = body.Id
|
||||
app.PlatformSecret = body.Secret
|
||||
for _, def := range body.Permits {
|
||||
app.Permits.Store(def.Id, &def.Permit)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import (
|
||||
"proxy-server/gateway/core"
|
||||
)
|
||||
|
||||
type PermitReq struct {
|
||||
Id int32 `json:"id"`
|
||||
core.Permit
|
||||
}
|
||||
type PermitReq []core.PermitDef
|
||||
|
||||
func Permit(ctx *fiber.Ctx) (err error) {
|
||||
|
||||
@@ -20,7 +17,7 @@ func Permit(ctx *fiber.Ctx) (err error) {
|
||||
}
|
||||
|
||||
// 获取请求参数
|
||||
req, err := core.Decrypt[[]PermitReq](&sec, app.PlatformSecret)
|
||||
req, err := core.Decrypt[PermitReq](&sec, app.PlatformSecret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user