-
Notifications
You must be signed in to change notification settings - Fork 0
/
method.go
53 lines (43 loc) · 1.27 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package autonats
import (
"go/ast"
)
// Describes a service method that's exposed to the service mesh
type Method struct {
Name string
Params []*Param
Results []*Param
imports map[string]bool
HandlerConcurrency int // Method handler concurrency
Timeout int // Method timeout
}
func MethodFromField(field *ast.Field) *Method {
fx := field.Type.(*ast.FuncType)
nParams := fx.Params.NumFields()
nResults := fx.Results.NumFields()
m := &Method{
Params: make([]*Param, nParams, nParams),
Results: make([]*Param, nResults, nResults),
imports: make(map[string]bool),
Name: field.Names[0].Name,
HandlerConcurrency: 0, // TODO: add custom tag/comment to define concurrency for each method
Timeout: 0, // TODO: add custom tag/comment to define timeout for each method
}
for ii, p := range fx.Params.List {
par := ParseParam(p)
m.Params[ii] = par
for k := range par.RequiredImports {
m.imports[k] = true
}
}
if fx.Results != nil && len(fx.Results.List) > 0 {
for ii, r := range fx.Results.List {
result := ParseParam(r)
m.Results[ii] = result
for k := range result.RequiredImports {
m.imports[k] = true
}
}
}
return m
}