mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-02 14:28:34 +00:00
* modify * update * add acl * add feature * update dockerfile * add deploy * update * update * plugins * plugins * update * update * update * fixed * remove * fixed * add log * update * fixed * update * fix config * add http api * add http api * resp * add config for work chan * update * fixed * update * disable trace * fixed * change acl * fixed * fixed res * dd * dd * ddd * dd * update * fixed * update * add * fixed * update key * add log * update * format * update * update auth * update * update readme * added * update * fixed * fixed * fix * upade * update * update
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
/* Copyright (c) 2018, joy.zhou <chowyu08@gmail.com>
|
|
*/
|
|
package acl
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
func SubscribeTopicSpilt(topic string) ([]string, error) {
|
|
subject := []byte(topic)
|
|
if bytes.IndexByte(subject, '#') != -1 {
|
|
if bytes.IndexByte(subject, '#') != len(subject)-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 PublishTopicSpilt(topic string) ([]string, error) {
|
|
subject := []byte(topic)
|
|
if bytes.IndexByte(subject, '#') != -1 || bytes.IndexByte(subject, '+') != -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
|
|
}
|