forked from goadesign/plugins
/
design.go
97 lines (88 loc) · 1.95 KB
/
design.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
90
91
92
93
94
95
96
97
package design
import (
. "goa.design/goa/dsl"
_ "goa.design/plugins/goakit"
)
var _ = API("archiver", func() {
Title("The goakit example downstream service")
Description("Archiver is a service that manages the content of HTTP responses")
})
var _ = Service("archiver", func() {
HTTP(func() {
Path("/archive")
})
Method("archive", func() {
Description("Archive HTTP response")
Payload(ArchivePayload)
Result(ArchiveMedia)
HTTP(func() {
POST("/")
Response(StatusOK)
})
})
Method("read", func() {
Description("Read HTTP response from archive")
Payload(func() {
Attribute("id", Int, "ID of archive", func() {
Minimum(0)
})
Required("id")
})
Result(ArchiveMedia)
Error("not_found")
Error("bad_request")
HTTP(func() {
GET("/{id}")
Response(StatusOK)
Response("not_found", StatusNotFound, func() {
Tag("code", "not_found")
})
Response("bad_request", StatusBadRequest, func() {
Tag("code", "bad_request")
})
})
})
})
var ArchivePayload = Type("ArchivePayload", func() {
Attribute("status", Int, "HTTP status", func() {
Minimum(0)
Example(200)
})
Attribute("body", String, "HTTP response body content")
Required("status", "body")
})
var ArchiveMedia = ResultType("application/vnd.goa.archive", func() {
Description("Archive is an HTTP response archive")
TypeName("ArchiveMedia")
Reference(ArchivePayload)
Attributes(func() {
Attribute("href", String, "The archive resouce href", func() {
Pattern("^/archive/[0-9]+$")
Example("/archive1/")
})
Attribute("status")
Attribute("body")
Required("href", "status", "body")
})
View("default", func() {
Attribute("href")
Attribute("status")
Attribute("body")
})
})
var _ = Service("health", func() {
HTTP(func() {
Path("/health")
})
Method("show", func() {
Description("Health check endpoint")
Result(String)
HTTP(func() {
GET("/")
Response(func() {
Code(StatusOK)
ContentType("text/plain")
})
})
})
})