package cmdn import ( "errors" "fmt" "regexp" "strings" ) type IResponse interface { // MessageID 消息ID MessageID() string } type PlainResp struct { ID string Command string Result string Err error } func (r *PlainResp) MessageID() string { return r.ID } func (r *PlainResp) GetResult() (string, error) { reg, _ := regexp.Compile(`\t`) result := strings.TrimSpace(reg.ReplaceAllString(r.Result, " ")) res := strings.Fields(result) l := len(res) if l > 0 { if res[0] == "=" { return strings.TrimSpace(strings.Join(res[1:], " ")), nil } else if res[0] == "?" { return "", errors.New(strings.Join(res[1:], " ")) } } return "", errors.New(fmt.Sprintf("错误(未知应答): %s", r.Err)) }