forked from goadesign/plugins
/
design.go
80 lines (68 loc) · 2.35 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
package design
import (
. "goa.design/goa/dsl"
_ "goa.design/plugins/zaplogger"
)
// API describes the global properties of the API server.
var _ = API("calc", func() {
Title("Calculator Service")
Description("HTTP service for adding numbers, a goa teaser")
// Server describes a single process listening for client requests. The DSL
// defines the set of services that the server hosts as well as hosts details.
Server("calc", func() {
Description("calc hosts the Calculator Service.")
// List the services hosted by this server.
Services("calc")
// List the Hosts and their transport URLs.
Host("development", func() {
Description("Development hosts.")
// Transport specific URLs, supported schemes are:
// 'http', 'https', 'grpc' and 'grpcs' with the respective default
// ports: 80, 443, 8080, 8443.
URI("http://localhost:8000/calc")
URI("grpc://localhost:8080")
})
Host("production", func() {
Description("Production hosts.")
// URIs can be parameterized using {param} notation.
URI("https://{version}.goa.design/calc")
URI("grpcs://{version}.goa.design")
// Variable describes a URI variable.
Variable("version", String, "API version", func() {
// URL parameters must have a default value and/or an
// enum validation.
Default("v1")
})
})
})
})
// Service describes a service
var _ = Service("calc", func() {
Description("The calc service performs operations on numbers")
// Method describes a service method (endpoint)
Method("add", func() {
// Payload describes the method payload.
// Here the payload is an object that consists of two fields.
Payload(func() {
// Attribute describes an object field
Attribute("a", Int, "Left operand")
Attribute("b", Int, "Right operand")
Required("a", "b")
})
// Result describes the method result.
// Here the result is a simple integer value.
Result(Int)
// HTTP describes the HTTP transport mapping.
HTTP(func() {
// Requests to the service consist of HTTP GET requests.
// The payload fields are encoded as path parameters.
GET("/add/{a}/{b}")
// Responses use a "200 OK" HTTP status.
// The result is encoded in the response body.
Response(StatusOK)
})
})
// Serve the file with relative path ../../gen/http/openapi.json for
// requests sent to /swagger.json.
Files("/swagger.json", "../../gen/http/openapi.json")
})