golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 line
524 B

  1. package utils
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. type Error string
  7. func (err Error) Error() string { return string(err) }
  8. var ErrNil = errors.New("redigo: nil returned")
  9. func Bytes(reply interface{}, err error) ([]byte, error) {
  10. if err != nil {
  11. return nil, err
  12. }
  13. switch reply := reply.(type) {
  14. case []byte:
  15. return reply, nil
  16. case string:
  17. return []byte(reply), nil
  18. case nil:
  19. return nil, ErrNil
  20. case Error:
  21. return nil, reply
  22. }
  23. return nil, fmt.Errorf("redigo: unexpected type for Bytes, got type %T", reply)
  24. }