Files
lone-services/pkg/ws/types.go
T
2026-10-21 13:29:03 +08:00

56 lines
1.2 KiB
Go

package ws
import (
"encoding/json"
"time"
)
const (
RedisKeyQRSession = "qr:session:"
RedisKeyQRShare = "qr:share:"
RedisKeyOssUpload = "oss:upload:task:"
RedisKeyTaskLights = "task:lights:"
RedisChannelQRPush = "ws:qr:push"
StatusPending = 1 // 待扫码
StatusScanned = 2 // 已扫码未登录
StatusLogined = 3 // 已扫码已登录
WsTypeLogin = 1 // 同意登录
WsTypeScanned = 2 // 拒绝授权 / 拒绝登录
WsTypeScan = 3 // 进入扫码页通知
SessionTTL = 5 * time.Minute
CodeOK = 200
MsgOK = "success"
CodeErr = 500
)
type Session struct {
Status int `json:"status"`
ClientCode string `json:"client_code,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
}
type Event struct {
SessionID string `json:"session_id"`
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}
func Success(data interface{}) Response {
return Response{Code: CodeOK, Message: MsgOK, Data: data}
}
func Fail(msg string) Response {
return Response{Code: CodeErr, Message: msg, Data: nil}
}