同步代码

This commit is contained in:
TsMask
2023-08-21 11:00:22 +08:00
parent 2735cc3009
commit 788f01674a
37 changed files with 2211 additions and 1 deletions

38
omc/msg.go Normal file
View File

@@ -0,0 +1,38 @@
package omc
// ErrorMsg ackLoginAlarm;result=fail;resDesc=username-error
func ErrorMsg(msgType string, reqID string, desc string) []byte {
msgBody := MsgBody{
MsgName: msgType,
Msg: make(map[string]string, 0),
}
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
}
func SuccessMsg(msgType string, reqID string, desc string) []byte {
msgBody := MsgBody{
MsgName: msgType,
Msg: make(map[string]string, 0),
}
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.Pack()
return msgBody.RawData
}

46
omc/omc_pack.go Normal file
View File

@@ -0,0 +1,46 @@
package omc
import (
"errors"
"fmt"
"strings"
)
type MsgBody struct {
UID string
RawData []byte
MsgName string
Msg map[string]string
Keys []string
}
// Decode
// reqLoginAlarm;user=yiy;key=qw#$@;type=msg
func (o *MsgBody) Decode() error {
multi := strings.Split(string(o.RawData), ";")
if len(multi) < 1 {
return errors.New("invalid msg body")
}
for i := 1; i < len(multi); i++ {
m := strings.Split(multi[i], "=")
if len(m) != 2 {
return errors.New("invalid msg body")
}
o.Msg[m[0]] = m[1]
}
return nil
}
// Pack
// 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])
multi = append(multi, item)
}
raw := strings.Join(multi, ";")
o.RawData = []byte(raw)
return nil
}

39
omc/omc_type.go Normal file
View File

@@ -0,0 +1,39 @@
package omc
const (
RealTimeAlarm = 0
ReqLoginAlarm = 1
AckLoginAlarm = 2
ReqSyncAlarmMsg = 3
AckSyncAlarmMsg = 4
ReqSyncAlarmFile = 5
AckSyncAlarmFile = 6
AckSyncAlarmFileResult = 7
ReqHeartBeat = 8
AckHeartBeat = 9
CloseConnAlarm = 10
ReqCMCALoginAlarm = 11
ReqCMCALoginSeq = 12
AckCMCALoginSeq = 13
)
//定义user type
const (
MSG = "msg"
FILE = "ftp"
)
func OrigSeverity(os string) int32 {
switch os {
case "Critical":
return 1
case "Major":
return 2
case "Minor":
return 3
case "Warning":
return 4
default:
return 0
}
}