-
Notifications
You must be signed in to change notification settings - Fork 0
/
method.go
89 lines (75 loc) · 2.24 KB
/
method.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
88
89
package controller
import (
"fmt"
"github.com/goadesign/goa"
"github.com/pei0804/goa-simple-sample/app"
)
// MethodController implements the method resource.
type MethodController struct {
*goa.Controller
}
// NewMethodController creates a method controller.
func NewMethodController(service *goa.Service) *MethodController {
return &MethodController{Controller: service.NewController("MethodController")}
}
// Etc runs the etc action.
func (c *MethodController) Etc(ctx *app.EtcMethodContext) error {
// MethodController_Etc: start_implement
// Put your logic here
// MethodController_Etc: end_implement
return ctx.OK([]byte(fmt.Sprintf("ID: %d, Type %d", ctx.ID, ctx.Type)))
}
// Follow runs the follow action.
func (c *MethodController) Follow(ctx *app.FollowMethodContext) error {
// MethodController_Follow: start_implement
// Put your logic here
var message string
// 何かのフォロー操作
if "PUT" == ctx.Request.Method {
message = "フォローした"
} else if "DELETE" == ctx.Request.Method {
message = "フォロー外した"
}
// MethodController_Follow: end_implement
res := &app.Message{}
res.Message = message
return ctx.OK(res)
}
// List runs the list action.
func (c *MethodController) List(ctx *app.ListMethodContext) error {
// MethodController_List: start_implement
// Put your logic here
var listType string
switch ctx.RequestURI {
//case client.ListMethodPath(): <---これでもいけるけど・・・って感じ 何かいい方法。
case "/api/v1/method/list":
listType = "ただの"
case "/api/v1/method/list/new":
listType = "新しい"
case "/api/v1/method/list/topic":
listType = "注目されている"
}
// MethodController_List: end_implement
res := make(app.UserTinyCollection, 2)
u1 := &app.UserTiny{
ID: 1,
Name: listType + "ユーザー1",
}
u2 := &app.UserTiny{
ID: 2,
Name: listType + "ユーザー2",
}
res[0] = u1
res[1] = u2
return ctx.OKTiny(res)
}
// Method runs the method action.
func (c *MethodController) Method(ctx *app.MethodMethodContext) error {
// MethodController_Method: start_implement
// Put your logic here
message := ctx.RequestURI
// MethodController_Method: end_implement
res := &app.Message{}
res.Message = message
return ctx.OK(res)
}