package mpd func (p *Player) Command(format string, args ...interface{}) error { command := newSimpleCommand(format, args...) p.simpleCommands <- command err := <-command.Err close(command.Err) return err } type simpleCommand struct { Format string Args []interface{} Err chan error } func newSimpleCommand(format string, args ...interface{}) *simpleCommand { return &simpleCommand{ Format: format, Args: args, Err: make(chan error, 1), } } func (p *Player) CommandData(format string, args ...interface{}) ([]string, error) { command := newDataCommand(format, args...) p.dataCommands <- command err := <-command.Err close(command.Err) return command.Lines, err } func newDataCommand(format string, args ...interface{}) *dataCommand { return &dataCommand{ Format: format, Args: args, Err: make(chan error, 1), } } type dataCommand struct { Format string Args []interface{} Lines []string Err chan error }