func (t *TermBackend) ListFiles(data interface{}, client server.ProtocolClient) error { files, err := ioutil.ReadDir(t.homeDir) filenames := []interface{}{} if err != nil { client.WriteError(err) client.Flush() } else { for _, f := range files { if !f.IsDir() { filenames = append(filenames, f.Name()) } } client.WriteArray(filenames) client.Flush() } return nil }
func (b *DefaultBackend) echo(data interface{}, client server.ProtocolClient) error { d, okInterface := data.([]interface{}) if okInterface { if len(d) == 0 { client.WriteString("") client.Flush() return nil } else { if len(d) == 1 { fmt.Printf("%v", d[0]) client.WriteInterface(d[0]) } else { client.WriteArray(d) } client.Flush() return nil } } else { b, _ := data.([][]byte) if len(b) == 0 { client.WriteString("") client.Flush() return nil } else { if len(b) == 1 { client.WriteString(string(b[0])) } else { s := make([]string, len(b)) for i, k := range b { s[i] = string(k) } client.WriteString(strings.Join(s, " ")) } client.Flush() return nil } } }