/
resources.go
71 lines (65 loc) · 1.4 KB
/
resources.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
package design
import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)
var _ = Resource("bottle", func() {
BasePath("/bottles")
DefaultMedia(Bottle)
Action("show", func() {
Description("Get bottle by id")
Routing(GET("/:bottleID"))
Params(func() {
Param("bottleID", Integer, "Bottle ID")
})
Response(OK)
Response(NotFound)
})
})
var _ = Resource("user", func() {
BasePath("/users")
DefaultMedia(User)
Action("index", func() {
Description("List users")
Routing(GET("/"))
Response(OK, func() {
Media(CollectionOf(User, func() {
View("default")
}))
})
Response(NotFound)
})
Action("show", func() {
Description("Get user by id")
Routing(GET("/:userID"))
Params(func() {
Param("userID", Integer, "User ID")
})
Response(OK)
Response(NotFound)
})
Action("create", func() {
Description("Create user")
Routing(POST("/"))
Payload(UserPayload)
Response(OK)
Response(NotFound)
})
Action("update", func() {
Description("Update user")
Routing(PATCH("/:userID"))
Params(func() {
Param("userID", Integer, "User ID")
})
Payload(UserPayload)
Response(OK)
Response(NotFound)
})
})
var _ = Resource("swagger", func() {
Origin("*", func() {
Methods("GET") // Allow all origins to retrieve the Swagger JSON (CORS)
})
Files("/swagger.json", "swagger/swagger.json")
Files("/swaggerui/*filepath", "swaggerui/dist")
})