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:
Felipe M 2025-07-15 14:45:11 +02:00
parent 2e2a95d7d6
commit d7ac783efc
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
3 changed files with 13 additions and 10 deletions

View file

@ -6,7 +6,7 @@ linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: {{.GoModule}}
local-prefixes: {{.GoModule.Name}}
govet:
check-shadowing: true
enable-all: true

View file

@ -33,10 +33,10 @@ endif
mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/mockgen@v1.6.0
mockgen -destination=server/command/mocks/mock_commands.go -package=mocks {{.GoModule}}/server/command Command
mockgen -destination=server/command/mocks/mock_commands.go -package=mocks {{.GoModule.Name}}/server/command Command
endif
## Show help documentation.
.PHONY: help
help:
@cat Makefile build/*.mk | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//g" | sed -e "s/^## //g" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
@cat Makefile build/*.mk | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//g" | sed -e "s/^## //g" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort

View file

@ -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
}
}