forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
method.go
35 lines (33 loc) · 821 Bytes
/
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
package dsl
import (
"goa.design/goa/eval"
"goa.design/goa/expr"
)
// Method defines a single service method.
//
// Method must appear in a Service expression.
//
// Method takes two arguments: the name of the method and the defining DSL.
//
// Example:
//
// Method("add", func() {
// Description("The add method returns the sum of A and B")
// Docs(func() {
// Description("Add docs")
// URL("http//adder.goa.design/docs/endpoints/add")
// })
// Payload(Operands)
// Result(Sum)
// Error(ErrInvalidOperands)
// })
//
func Method(name string, fn func()) {
s, ok := eval.Current().(*expr.ServiceExpr)
if !ok {
eval.IncompatibleDSL()
return
}
ep := &expr.MethodExpr{Name: name, Service: s, DSLFunc: fn}
s.Methods = append(s.Methods, ep)
}