checker.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Code generated by goctl. DO NOT EDIT!
  2. // Source: check.proto
  3. //go:generate mockgen -destination ./checker_mock.go -package checker -source $GOFILE
  4. package checker
  5. import (
  6. "context"
  7. check "bookstore/rpc/check/pb"
  8. "github.com/tal-tech/go-zero/core/jsonx"
  9. "github.com/tal-tech/go-zero/zrpc"
  10. )
  11. type (
  12. Checker interface {
  13. Check(ctx context.Context, in *CheckReq) (*CheckResp, error)
  14. }
  15. defaultChecker struct {
  16. cli zrpc.Client
  17. }
  18. )
  19. func NewChecker(cli zrpc.Client) Checker {
  20. return &defaultChecker{
  21. cli: cli,
  22. }
  23. }
  24. func (m *defaultChecker) Check(ctx context.Context, in *CheckReq) (*CheckResp, error) {
  25. var request check.CheckReq
  26. bts, err := jsonx.Marshal(in)
  27. if err != nil {
  28. return nil, errJsonConvert
  29. }
  30. err = jsonx.Unmarshal(bts, &request)
  31. if err != nil {
  32. return nil, errJsonConvert
  33. }
  34. client := check.NewCheckerClient(m.cli.Conn())
  35. resp, err := client.Check(ctx, &request)
  36. if err != nil {
  37. return nil, err
  38. }
  39. var ret CheckResp
  40. bts, err = jsonx.Marshal(resp)
  41. if err != nil {
  42. return nil, errJsonConvert
  43. }
  44. err = jsonx.Unmarshal(bts, &ret)
  45. if err != nil {
  46. return nil, errJsonConvert
  47. }
  48. return &ret, nil
  49. }