This commit is contained in:
TsMask
2023-08-21 11:02:58 +08:00
parent 788f01674a
commit 4a3e6d7d67
26 changed files with 664 additions and 50 deletions

View File

@@ -8,12 +8,9 @@ func ErrorMsg(msgType string, reqID string, desc string) []byte {
}
if reqID != "" {
msgBody.Msg["reqId"] = reqID
msgBody.Keys = append(msgBody.Keys, "reqId")
}
msgBody.Msg["result"] = "fail"
msgBody.Keys = append(msgBody.Keys, "result")
msgBody.Msg["resDesc"] = desc
msgBody.Keys = append(msgBody.Keys, "resDesc")
msgBody.Pack()
return msgBody.RawData
}
@@ -25,13 +22,9 @@ func SuccessMsg(msgType string, reqID string, desc string) []byte {
}
if reqID != "" {
msgBody.Msg["reqId"] = reqID
msgBody.Keys = append(msgBody.Keys, "reqId")
}
msgBody.Msg["result"] = "succ"
msgBody.Keys = append(msgBody.Keys, "result")
//msgBody.Msg["resDesc"] = desc
msgBody.Msg["resDesc"] = "succ"
msgBody.Keys = append(msgBody.Keys, "resDesc")
msgBody.Msg["resDesc"] = desc
msgBody.Pack()
return msgBody.RawData

View File

@@ -11,11 +11,10 @@ type MsgBody struct {
RawData []byte
MsgName string
Msg map[string]string
Keys []string
}
// Decode
// reqLoginAlarm;user=yiy;key=qw#$@;type=msg
//reqLoginAlarm;user=yiy;key=qw#$@;type=msg
func (o *MsgBody) Decode() error {
multi := strings.Split(string(o.RawData), ";")
if len(multi) < 1 {
@@ -32,12 +31,12 @@ func (o *MsgBody) Decode() error {
}
// Pack
// reqLoginAlarm;user=yiy;key=qw#$@;type=msg
//reqLoginAlarm;user=yiy;key=qw#$@;type=msg
func (o *MsgBody) Pack() error {
var multi []string
multi = append(multi, o.MsgName)
for _, key := range o.Keys {
item := fmt.Sprintf("%s=%s", key, o.Msg[key])
for i, v := range o.Msg {
item := fmt.Sprintf("%s=%s", i, v)
multi = append(multi, item)
}
raw := strings.Join(multi, ";")