Example #1
0
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
		}
	}
}