style: pack commandParse and socket server to different packages

This commit is contained in:
2026-04-04 18:00:59 +08:00
parent b367323801
commit 8aa30b434b
3 changed files with 65 additions and 43 deletions

41
command/commandParse.go Normal file
View File

@@ -0,0 +1,41 @@
package command
import (
"strings"
)
func getTextMiddle(text, left, right string) string {
start := 0
if left != "" {
idx := strings.Index(text, left)
if idx == -1 {
return ""
}
start = idx + len(left)
}
if right == "" {
if start > len(text) {
return ""
}
return text[start:]
}
endIdx := strings.Index(text[start:], right)
if endIdx == -1 {
return ""
}
return text[start : start+endIdx]
}
func getCommand(content string) string {
return getTextMiddle(content, "[", "]")
}
func parseCommand(content, cmdType string) string {
return getTextMiddle(content, "<" + cmdType + ">", "</" + cmdType + ">")
}
func ExecuteCommand(input string) error {
return nil
}