12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package service
- import (
- "context"
- "github.com/go-kit/kit/endpoint"
- "git.chuangxin1.com/csacred/toolkit/example/cuser/define"
- )
- // Endpoints define
- type Endpoints struct {
- UserListEndpoint endpoint.Endpoint
- UserProfileEndpoint endpoint.Endpoint
- UserSignInEndpoint endpoint.Endpoint
- UserChangePwdEndpoint endpoint.Endpoint
- }
- // GenServerEndpoints service to endpoints
- func GenServerEndpoints(s UserServicer) Endpoints {
- return Endpoints{
- UserListEndpoint: genUserListEndpoint(s),
- UserProfileEndpoint: genUserProfileEndpoint(s),
- UserSignInEndpoint: genUserSignInEndpoint(s),
- UserChangePwdEndpoint: genUserChangePwdEndpoint(s),
- }
- }
- func genUserListEndpoint(s UserServicer) endpoint.Endpoint {
- return func(
- ctx context.Context,
- request interface{}) (response interface{}, err error) {
- req := request.(define.FormUser)
- response, err = s.List(ctx, req)
- return
- }
- }
- func genUserProfileEndpoint(s UserServicer) endpoint.Endpoint {
- return func(
- ctx context.Context,
- request interface{}) (response interface{}, err error) {
- req := request.(define.FormID)
- response, err = s.Profile(ctx, req)
- //response = toolkit.NewReplyData(toolkit.ErrOk)
- //err = nil
- return
- }
- }
- func genUserSignInEndpoint(s UserServicer) endpoint.Endpoint {
- return func(
- ctx context.Context,
- request interface{}) (response interface{}, err error) {
- req := request.(define.FormUserSignIn)
- response, err = s.SignIn(ctx, req)
- return
- }
- }
- func genUserChangePwdEndpoint(s UserServicer) endpoint.Endpoint {
- return func(
- ctx context.Context,
- request interface{}) (response interface{}, err error) {
- req := request.(define.FormUserChangePwd)
- response, err = s.ChangePwd(ctx, req)
- return
- }
- }
|