ivankatliarchuk commented on code in PR #268:
URL: https://github.com/apache/skywalking-eyes/pull/268#discussion_r3036721131
##########
pkg/deps/golang.go:
##########
@@ -38,27 +39,60 @@ type GoModResolver struct {
Resolver
}
+const (
+ goModFileName = "go.mod"
+)
+
+var (
+ goModuleDirective = regexp.MustCompile(`(?m)^\s*module\s+\S`)
+ goVersionDirective = regexp.MustCompile(`(?m)^\s*go\s+\d`)
+ possibleLicenseFileName =
regexp.MustCompile(`(?i)^LICENSE|LICENCE(\.txt)?|COPYING(\.txt)?$`)
+)
+
func (resolver *GoModResolver) CanResolve(file string) bool {
base := filepath.Base(file)
logger.Log.Debugln("Base name:", base)
- return base == "go.mod"
+ return strings.HasSuffix(base, ".mod")
+}
+
+func validateGoModFile(file string) error {
+ content, err := os.ReadFile(file)
+ if err != nil {
+ return err
+ }
+ if !goModuleDirective.Match(content) ||
!goVersionDirective.Match(content) {
+ return fmt.Errorf("%v is not a valid Go module file", file)
+ }
Review Comment:
relaxed
##########
pkg/deps/golang.go:
##########
@@ -38,27 +39,60 @@ type GoModResolver struct {
Resolver
}
+const (
+ goModFileName = "go.mod"
+)
+
+var (
+ goModuleDirective = regexp.MustCompile(`(?m)^\s*module\s+\S`)
+ goVersionDirective = regexp.MustCompile(`(?m)^\s*go\s+\d`)
+ possibleLicenseFileName =
regexp.MustCompile(`(?i)^LICENSE|LICENCE(\.txt)?|COPYING(\.txt)?$`)
Review Comment:
resolved
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]