-
Notifications
You must be signed in to change notification settings - Fork 232
/
usage.go
58 lines (47 loc) · 1.02 KB
/
usage.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
package api
import (
"go/ast"
"encr.dev/v2/parser/resource/usage"
)
type CallUsage struct {
usage.Base
// Endpoint is the endpoint being called.
Endpoint *Endpoint
// Call is the function call expression.
Call *ast.CallExpr
}
type ReferenceUsage struct {
usage.Base
// Endpoint is the endpoint being referenced.
Endpoint *Endpoint
// Ref is the reference expression.
Ref ast.Expr
}
func ResolveEndpointUsage(data usage.ResolveData, ep *Endpoint) usage.Usage {
switch expr := data.Expr.(type) {
case *usage.FuncCall:
return &CallUsage{
Base: usage.Base{
File: expr.File,
Bind: expr.Bind,
Expr: expr,
},
Endpoint: ep,
Call: expr.Call,
}
case *usage.Other:
return &ReferenceUsage{
Base: usage.Base{
File: expr.File,
Bind: expr.Bind,
Expr: expr,
},
Endpoint: ep,
Ref: expr.BindRef,
}
}
// Check if the resource is referenced in a permissible location.
// Walk the stack to find the
data.Errs.Add(ErrInvalidEndpointUsage.AtGoNode(data.Expr))
return nil
}