endpoint.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package service
  2. import (
  3. "context"
  4. "github.com/go-kit/kit/endpoint"
  5. "git.chuangxin1.com/csacred/toolkit/example/cuser/define"
  6. )
  7. // Endpoints define
  8. type Endpoints struct {
  9. UserListEndpoint endpoint.Endpoint
  10. UserProfileEndpoint endpoint.Endpoint
  11. UserSignInEndpoint endpoint.Endpoint
  12. UserChangePwdEndpoint endpoint.Endpoint
  13. }
  14. // GenServerEndpoints service to endpoints
  15. func GenServerEndpoints(s UserServicer) Endpoints {
  16. return Endpoints{
  17. UserListEndpoint: genUserListEndpoint(s),
  18. UserProfileEndpoint: genUserProfileEndpoint(s),
  19. UserSignInEndpoint: genUserSignInEndpoint(s),
  20. UserChangePwdEndpoint: genUserChangePwdEndpoint(s),
  21. }
  22. }
  23. func genUserListEndpoint(s UserServicer) endpoint.Endpoint {
  24. return func(
  25. ctx context.Context,
  26. request interface{}) (response interface{}, err error) {
  27. req := request.(define.FormUser)
  28. response, err = s.List(ctx, req)
  29. return
  30. }
  31. }
  32. func genUserProfileEndpoint(s UserServicer) endpoint.Endpoint {
  33. return func(
  34. ctx context.Context,
  35. request interface{}) (response interface{}, err error) {
  36. req := request.(define.FormID)
  37. response, err = s.Profile(ctx, req)
  38. //response = toolkit.NewReplyData(toolkit.ErrOk)
  39. //err = nil
  40. return
  41. }
  42. }
  43. func genUserSignInEndpoint(s UserServicer) endpoint.Endpoint {
  44. return func(
  45. ctx context.Context,
  46. request interface{}) (response interface{}, err error) {
  47. req := request.(define.FormUserSignIn)
  48. response, err = s.SignIn(ctx, req)
  49. return
  50. }
  51. }
  52. func genUserChangePwdEndpoint(s UserServicer) endpoint.Endpoint {
  53. return func(
  54. ctx context.Context,
  55. request interface{}) (response interface{}, err error) {
  56. req := request.(define.FormUserChangePwd)
  57. response, err = s.ChangePwd(ctx, req)
  58. return
  59. }
  60. }