Client.Hello, Client.Lookup and parseReply

This commit is contained in:
Henry
2014-02-09 18:40:51 +01:00
parent 3fa2f2ef68
commit 9e21061f3f
6 changed files with 350 additions and 0 deletions

36
replyParser.go Normal file
View File

@ -0,0 +1,36 @@
package goSam
import (
"fmt"
"strings"
)
type Reply struct {
Topic string
Type string
Pairs map[string]string
}
func parseReply(line string) (r *Reply, err error) {
parts := strings.Split(line, " ")
if len(parts) < 3 {
return nil, fmt.Errorf("Malformed Reply.\n%s\n", line)
}
r = &Reply{
Topic: parts[0],
Type: parts[1],
Pairs: make(map[string]string, len(parts)-2),
}
for _, v := range parts[2:] {
kvPair := strings.Split(v, "=")
if len(kvPair) != 2 {
return nil, fmt.Errorf("Malformed key-value-pair.\n%s\n", kvPair)
}
r.Pairs[kvPair[0]] = kvPair[1]
}
return
}