import "bufio"
import "strings"
+var cmdHandler = map[string]func([]string,string) {
+ "test":handleCmdTest,
+}
+
+
func readLineSafe(rw *bufio.ReadWriter) (string, error) {
wasPrefix:=false
var line string
for {
line,err:=readLineSafe(client)
if err != nil {
- fmt.Println(err.Error())
+ if err.Error() != "EOF" {
+ fmt.Printf("Error: readLineSafe returned %v\n",err.Error())
+ } else {
+ fmt.Printf("Connection closed by remote host\n");
+ }
c.Close()
return
}
func handleCmd(tokens []string, remainStr string) {
cmd:=tokens[0]
- fmt.Printf("Handling Cmd: %v\n", cmd)
+ func_ptr,present := cmdHandler[cmd]
+ if present {
+ func_ptr(tokens, remainStr)
+ } else {
+ fmt.Printf("Error: unknown Cmd: %v\n", cmd)
+ }
}
+
+func handleCmdTest(tokens []string, remainStr string) {
+ //cmd:=tokens[0]
+ fmt.Printf("Test: %v\n", remainStr)
+}
+
func main() {
ln, err := net.Listen("unix", "/tmp/test.sock")
if err != nil {