@@ -10,9 +10,7 @@ import (
1010)
1111
1212// Goroutine checks that go statements propagate context.
13- type Goroutine struct {
14- Derivers * deriver.Matcher
15- }
13+ type Goroutine struct {}
1614
1715// Name returns the checker name for ignore directive matching.
1816func (* Goroutine ) Name () ignore.CheckerName {
@@ -83,7 +81,12 @@ func (*Goroutine) checkFromAST(cctx *probe.Context, stmt *ast.GoStmt) bool {
8381
8482// GoroutineDerive checks that go statements call a deriver function.
8583type GoroutineDerive struct {
86- Derivers * deriver.Matcher
84+ derivers * deriver.Matcher
85+ }
86+
87+ // NewGoroutineDerive creates a new GoroutineDerive checker.
88+ func NewGoroutineDerive (derivers * deriver.Matcher ) * GoroutineDerive {
89+ return & GoroutineDerive {derivers : derivers }
8790}
8891
8992// Name returns the checker name for ignore directive matching.
@@ -93,7 +96,7 @@ func (*GoroutineDerive) Name() ignore.CheckerName {
9396
9497// CheckGoStmt checks a go statement for deriver function calls.
9598func (c * GoroutineDerive ) CheckGoStmt (cctx * probe.Context , stmt * ast.GoStmt ) * internal.Result {
96- if c .Derivers == nil || c .Derivers .IsEmpty () {
99+ if c .derivers == nil || c .derivers .IsEmpty () {
97100 return internal .OK ()
98101 }
99102
@@ -108,7 +111,7 @@ func (c *GoroutineDerive) CheckGoStmt(cctx *probe.Context, stmt *ast.GoStmt) *in
108111 return result
109112 }
110113
111- if c .Derivers .SatisfiesAnyGroup (cctx .Pass , lit .Body ) {
114+ if c .derivers .SatisfiesAnyGroup (cctx .Pass , lit .Body ) {
112115 return internal .OK ()
113116 }
114117 return internal .Fail (c .message ())
@@ -132,11 +135,11 @@ func (c *GoroutineDerive) CheckGoStmt(cctx *probe.Context, stmt *ast.GoStmt) *in
132135}
133136
134137func (c * GoroutineDerive ) message () string {
135- return "goroutine should call " + c .Derivers .Original + " to derive context"
138+ return "goroutine should call " + c .derivers .Original + " to derive context"
136139}
137140
138141func (c * GoroutineDerive ) deferMessage () string {
139- return "goroutine calls " + c .Derivers .Original + " in defer, but it should be called at goroutine start"
142+ return "goroutine calls " + c .derivers .Original + " in defer, but it should be called at goroutine start"
140143}
141144
142145func (c * GoroutineDerive ) checkFromSSA (cctx * probe.Context , lit * ast.FuncLit ) (* internal.Result , bool ) {
@@ -149,7 +152,7 @@ func (c *GoroutineDerive) checkFromSSA(cctx *probe.Context, lit *ast.FuncLit) (*
149152 return nil , false
150153 }
151154
152- result := cctx .Tracer .ClosureCallsDeriver (ssaFn , c .Derivers )
155+ result := cctx .Tracer .ClosureCallsDeriver (ssaFn , c .derivers )
153156
154157 if result .FoundAtStart {
155158 return internal .OK (), true
@@ -172,7 +175,7 @@ func (c *GoroutineDerive) checkIdent(cctx *probe.Context, ident *ast.Ident) bool
172175 return true
173176 }
174177
175- return c .Derivers .SatisfiesAnyGroup (cctx .Pass , funcLit .Body )
178+ return c .derivers .SatisfiesAnyGroup (cctx .Pass , funcLit .Body )
176179}
177180
178181func (c * GoroutineDerive ) checkHigherOrder (cctx * probe.Context , innerCall * ast.CallExpr ) bool {
@@ -214,7 +217,7 @@ func (c *GoroutineDerive) factoryReturnsCallingFunc(cctx *probe.Context, factory
214217 callsDeriver = true
215218 return false
216219 }
217- if c .Derivers .SatisfiesAnyGroup (cctx .Pass , fl .Body ) {
220+ if c .derivers .SatisfiesAnyGroup (cctx .Pass , fl .Body ) {
218221 callsDeriver = true
219222 return false
220223 }
@@ -243,7 +246,7 @@ func (c *GoroutineDerive) returnedValueCalls(cctx *probe.Context, result ast.Exp
243246 if cctx .FuncLitHasContextParam (innerFuncLit ) {
244247 return true
245248 }
246- return c .Derivers .SatisfiesAnyGroup (cctx .Pass , innerFuncLit .Body )
249+ return c .derivers .SatisfiesAnyGroup (cctx .Pass , innerFuncLit .Body )
247250 }
248251
249252 ident , ok := result .(* ast.Ident )
@@ -259,5 +262,5 @@ func (c *GoroutineDerive) returnedValueCalls(cctx *probe.Context, result ast.Exp
259262 if cctx .FuncLitHasContextParam (innerFuncLit ) {
260263 return true
261264 }
262- return c .Derivers .SatisfiesAnyGroup (cctx .Pass , innerFuncLit .Body )
265+ return c .derivers .SatisfiesAnyGroup (cctx .Pass , innerFuncLit .Body )
263266}
0 commit comments