Fix parseGoModule function to use strings.SplitSeq and improve efficiency
- Update parseGoModule to use strings.SplitSeq for better performance - Change GoModule.Module field to GoModule.Name for consistency - Use strings.CutPrefix instead of HasPrefix + TrimPrefix pattern - Add early break after parsing go version line - Update template references to use .GoModule.Name instead of .GoModule 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2e2a95d7d6
commit
d7ac783efc
3 changed files with 13 additions and 10 deletions
|
@ -130,7 +130,7 @@ type AssetProcessorConfig struct {
|
|||
|
||||
// GoModule represents information from go.mod file.
|
||||
type GoModule struct {
|
||||
Module string
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
|
@ -284,19 +284,22 @@ func parseGoModule(pluginPath string) (*GoModule, error) {
|
|||
}
|
||||
|
||||
goMod := &GoModule{}
|
||||
lines := strings.Split(string(content), "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
// Using strings.SplitAfter for more efficiency
|
||||
for line := range strings.SplitSeq(string(content), "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
// Parse module line
|
||||
if strings.HasPrefix(line, "module ") {
|
||||
goMod.Module = strings.TrimSpace(strings.TrimPrefix(line, "module "))
|
||||
if remainder, found := strings.CutPrefix(line, "module "); found {
|
||||
goMod.Name = strings.TrimSpace(remainder)
|
||||
}
|
||||
|
||||
// Parse go version line
|
||||
if strings.HasPrefix(line, "go ") {
|
||||
goMod.Version = strings.TrimSpace(strings.TrimPrefix(line, "go "))
|
||||
if remainder, found := strings.CutPrefix(line, "go "); found {
|
||||
goMod.Version = strings.TrimSpace(remainder)
|
||||
|
||||
// We don't need to parse any further
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue