-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
45 lines (39 loc) · 1.23 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
package proclaim
import (
"context"
"github.com/go-kit/kit/endpoint"
"github.com/fuhsicloud/fuhsicloud/src/util/encode"
)
type proclaimListRequest struct {
Name string
Page, Limit int
}
type proclaimRequest struct {
Id int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
ProclaimType string `json:"proclaim_type"`
Namespace []string `json:"namespace"`
UserList []string `json:"userlist"`
}
func makeGetEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(proclaimRequest)
res, err := s.Get(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.(proclaimRequest)
err := s.Post(ctx, req)
return encode.Response{Err: err, Data: nil}, err
}
}
func makeListEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(proclaimListRequest)
res, err := s.List(ctx, req.Name, req.Page, req.Limit)
return encode.Response{Err: err, Data: res}, err
}
}