Restruct (#34)

* modify

* remove

* modify

* modify

* remove no use

* add online/offline notification

* modify

* format log

* add reference
This commit is contained in:
joy.zhou
2018-12-26 14:51:13 +08:00
committed by GitHub
parent 84e7fe2490
commit 7547ad3bdc
16 changed files with 1232 additions and 714 deletions

View File

@@ -7,10 +7,8 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"errors"
"io"
"reflect"
"strings"
"time"
)
@@ -48,47 +46,6 @@ const (
QosFailure = 0x80
)
func SubscribeTopicCheckAndSpilt(topic string) ([]string, error) {
if strings.Index(topic, "#") != -1 && strings.Index(topic, "#") != len(topic)-1 {
return nil, errors.New("Topic format error with index of #")
}
re := strings.Split(topic, "/")
for i, v := range re {
if i != 0 && i != (len(re)-1) {
if v == "" {
return nil, errors.New("Topic format error with index of //")
}
if strings.Contains(v, "+") && v != "+" {
return nil, errors.New("Topic format error with index of +")
}
} else {
if v == "" {
re[i] = "/"
}
}
}
return re, nil
}
func PublishTopicCheckAndSpilt(topic string) ([]string, error) {
if strings.Index(topic, "#") != -1 || strings.Index(topic, "+") != -1 {
return nil, errors.New("Publish Topic format error with + and #")
}
re := strings.Split(topic, "/")
for i, v := range re {
if v == "" {
if i != 0 && i != (len(re)-1) {
return nil, errors.New("Topic format error with index of //")
} else {
re[i] = "/"
}
}
}
return re, nil
}
func equal(k1, k2 interface{}) bool {
if reflect.TypeOf(k1) != reflect.TypeOf(k2) {
return false