4cca2c53decd9a7ebabeeb67bf622739deb4b301.svn-base 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package endpoint
  2. import (
  3. "context"
  4. "github.com/go-kit/kit/endpoint"
  5. "github.com/longjoy/micro-go-course/section24/goods/service"
  6. )
  7. type GoodsEndpoints struct {
  8. GoodsDetailEndpoint endpoint.Endpoint
  9. }
  10. // 服务发现请求结构体
  11. type GoodsDetailRequest struct {
  12. Id string
  13. }
  14. // 服务发现响应结构体
  15. type GoodsDetailResponse struct {
  16. Detail service.GoodsDetailVO `json:"detail"`
  17. Error string `json:"error"`
  18. }
  19. // 创建服务发现的 Endpoint
  20. func MakeGoodsDetailEndpoint(svc service.Service) endpoint.Endpoint {
  21. return func(ctx context.Context, request interface{}) (response interface{}, err error) {
  22. req := request.(GoodsDetailRequest)
  23. detail, err := svc.GetGoodsDetail(ctx, req.Id)
  24. var errString = ""
  25. if err != nil {
  26. errString = err.Error()
  27. return &GoodsDetailResponse{
  28. Detail: detail,
  29. Error: errString,
  30. }, nil
  31. }
  32. return &GoodsDetailResponse{
  33. Detail: detail,
  34. Error: errString,
  35. }, nil
  36. }
  37. }