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

response.go 782 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package mq
  2. import (
  3. "gitlink.org.cn/cloudream/common/consts/errorcode"
  4. )
  5. type CodeMessage struct {
  6. Code string `json:"code"`
  7. Message string `json:"message"`
  8. }
  9. func (msg *CodeMessage) IsOK() bool {
  10. return msg.Code == errorcode.OK
  11. }
  12. func (msg *CodeMessage) IsFailed() bool {
  13. return !msg.IsOK()
  14. }
  15. func OK() *CodeMessage {
  16. return &CodeMessage{
  17. Code: errorcode.OK,
  18. Message: "",
  19. }
  20. }
  21. func Failed(errCode string, msg string) *CodeMessage {
  22. return &CodeMessage{
  23. Code: errCode,
  24. Message: msg,
  25. }
  26. }
  27. func ReplyFailed[T any](errCode string, msg string) (*T, *CodeMessage) {
  28. return nil, &CodeMessage{
  29. Code: errCode,
  30. Message: msg,
  31. }
  32. }
  33. func ReplyOK[T any](val T) (*T, *CodeMessage) {
  34. return &val, &CodeMessage{
  35. Code: errorcode.OK,
  36. Message: "",
  37. }
  38. }

公共库