ca60ae9f6a336307d10e19483f0d5b3cd77fdcda.svn-base 933 B

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