parse.gno
0.65 Kb ยท 25 lines
1package message
2
3import "strings"
4
5// ParseFunc parses a raw message and returns the message function
6// type extracted from the remainder of the message.
7func ParseFunc(rawMsg string) (FuncType, string) {
8 funcType, remainder := parseFirstToken(rawMsg)
9 return FuncType(funcType), remainder
10}
11
12// ParseID parses a raw message and returns the ID extracted from
13// the remainder of the message.
14func ParseID(rawMsg string) (string, string) {
15 return parseFirstToken(rawMsg)
16}
17
18func parseFirstToken(rawMsg string) (string, string) {
19 msgParts := strings.SplitN(rawMsg, ",", 2)
20 if len(msgParts) < 2 {
21 return msgParts[0], ""
22 }
23
24 return msgParts[0], msgParts[1]
25}