forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc.go
39 lines (35 loc) · 954 Bytes
/
grpc.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
package expr
type (
// GRPCExpr contains the API level gRPC specific expressions.
GRPCExpr struct {
// Services contains the gRPC services created by the DSL.
Services []*GRPCServiceExpr
// Errors lists the error gRPC error responses defined globally.
Errors []*GRPCErrorExpr
}
)
// Service returns the service with the given name if any.
func (g *GRPCExpr) Service(name string) *GRPCServiceExpr {
for _, res := range g.Services {
if res.Name() == name {
return res
}
}
return nil
}
// ServiceFor creates a new or returns the existing service definition for
// the given service.
func (g *GRPCExpr) ServiceFor(s *ServiceExpr) *GRPCServiceExpr {
if res := g.Service(s.Name); res != nil {
return res
}
res := &GRPCServiceExpr{
ServiceExpr: s,
}
g.Services = append(g.Services, res)
return res
}
// EvalName returns the name printed in case of evaluation error.
func (g *GRPCExpr) EvalName() string {
return "API GRPC"
}