-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
executable file
·49 lines (37 loc) · 1.21 KB
/
router.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
// Code generated by jrpc. DO NOT EDIT.
package handler
import (
context "context"
router "github.com/shadracnicholas/home-automation/libraries/go/router"
taxi "github.com/shadracnicholas/home-automation/libraries/go/taxi"
def "github.com/shadracnicholas/home-automation/service.user/def"
)
type service interface {
GetUser(ctx context.Context, body *def.GetUserRequest) (*def.GetUserResponse, error)
ListUsers(ctx context.Context, body *def.ListUsersRequest) (*def.ListUsersResponse, error)
}
// NewRouter creates a new router for this service
func NewRouter(s service) *router.Router {
r := router.New()
r.RegisterHandler("GET", "/user", func(ctx context.Context, decode taxi.Decoder) (interface{}, error) {
body := &def.GetUserRequest{}
if err := decode(body); err != nil {
return nil, err
}
if err := body.Validate(); err != nil {
return nil, err
}
return s.GetUser(ctx, body)
})
r.RegisterHandler("GET", "/users", func(ctx context.Context, decode taxi.Decoder) (interface{}, error) {
body := &def.ListUsersRequest{}
if err := decode(body); err != nil {
return nil, err
}
if err := body.Validate(); err != nil {
return nil, err
}
return s.ListUsers(ctx, body)
})
return r
}