This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 206
/
endpoint.go
87 lines (75 loc) · 2.41 KB
/
endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @Time : 2019-07-17 14:17
* @Author : solacowa@gmail.com
* @File : endpoint
* @Software: GoLand
*/
package member
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/kplcloud/kplcloud/src/util/encode"
)
type getMemberRequest struct {
Id int64 `json:"id"`
}
type memberRequest struct {
Id int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
State int64 `json:"state"`
Namespaces []string `json:"namespace"`
Roles []int64 `json:"role"`
}
type listMemberRequest struct {
Page int
Limit int
Email string
}
func makeNamespacesEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
res, err := s.Namespaces(ctx)
return encode.Response{Err: err, Data: res}, err
}
}
func makeDetailEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(getMemberRequest)
res, err := s.Detail(ctx, req.Id)
return encode.Response{Err: err, Data: res}, err
}
}
func makePostEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(memberRequest)
err := s.Post(ctx, req.Username, req.Email, req.Password, req.State, req.Namespaces, req.Roles)
return encode.Response{Err: err}, err
}
}
func makeUpdateEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(memberRequest)
err := s.Update(ctx, req.Id, req.Username, req.Email, req.Password, req.State, req.Namespaces, req.Roles)
return encode.Response{Err: err}, err
}
}
func makeListEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(listMemberRequest)
res, err := s.List(ctx, req.Page, req.Limit, req.Email)
return encode.Response{Err: err, Data: res}, err
}
}
func makeMeEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
res, err := s.Me(ctx)
return encode.Response{Err: err, Data: res}, err
}
}
func makeAllEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
res, err := s.All(ctx)
return encode.Response{Err: err, Data: res}, err
}
}