@@ -19,6 +19,8 @@ namespace Microsoft.ComponentDetection.Detectors.Go;
1919
2020public class GoComponentDetector : FileComponentDetector
2121{
22+ private const string StartString = "require " ;
23+
2224 private static readonly Regex GoSumRegex = new (
2325 @"(?<name>.*)\s+(?<version>.*?)(/go\.mod)?\s+(?<hash>.*)" ,
2426 RegexOptions . Compiled | RegexOptions . ExplicitCapture | RegexOptions . IgnoreCase ) ;
@@ -287,7 +289,6 @@ private async Task ParseGoModFileAsync(
287289 GoGraphTelemetryRecord goGraphTelemetryRecord )
288290 {
289291 using var reader = new StreamReader ( file . Stream ) ;
290- var startString = "require " ;
291292
292293 // There can be multiple require( ) sections in go 1.17+. loop over all of them.
293294 while ( ! reader . EndOfStream )
@@ -303,9 +304,9 @@ private async Task ParseGoModFileAsync(
303304
304305 // In go >= 1.17, direct dependencies are listed as "require x/y v1.2.3", and transitive dependencies
305306 // are listed in the require () section
306- if ( line . StartsWith ( startString ) )
307+ if ( line . StartsWith ( StartString ) )
307308 {
308- this . TryRegisterDependencyFromModLine ( line [ startString . Length ..] , singleFileComponentRecorder ) ;
309+ this . TryRegisterDependencyFromModLine ( line [ StartString . Length ..] , singleFileComponentRecorder ) ;
309310 }
310311
311312 line = await reader . ReadLineAsync ( ) ;
0 commit comments