check telegram string

This commit is contained in:
w1ndyb0y
2020-12-21 16:18:08 +08:00
parent 8a116818cf
commit 481870cea9
2 changed files with 43 additions and 3 deletions
+38
View File
@@ -0,0 +1,38 @@
package utils
import (
"log"
"regexp"
"strings"
)
const (
StartTag = "ZCZC"
EndTag = "NNNN"
Expression = "(?s)ZCZC.*NNNN"
)
var buffer []byte
func Append(data []byte) {
buffer = append(buffer, data...)
if buffer[len(buffer)-1] == '\r' {
buffer = append(buffer, '\n')
}
check()
}
func check() {
teleString := string(buffer)
if strings.Index(teleString, EndTag) > 0 {
exp, _ := regexp.Compile(Expression)
telegram := exp.FindString(string(buffer))
if len(telegram) > 0 {
log.Println("telegram : ", telegram)
buffer = nil
//TODO save telegram
}
}
}