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
|
@ -6,7 +6,7 @@ linters-settings:
|
||||||
gofmt:
|
gofmt:
|
||||||
simplify: true
|
simplify: true
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: {{.GoModule}}
|
local-prefixes: {{.GoModule.Name}}
|
||||||
govet:
|
govet:
|
||||||
check-shadowing: true
|
check-shadowing: true
|
||||||
enable-all: true
|
enable-all: true
|
||||||
|
|
|
@ -33,10 +33,10 @@ endif
|
||||||
mock:
|
mock:
|
||||||
ifneq ($(HAS_SERVER),)
|
ifneq ($(HAS_SERVER),)
|
||||||
go install github.com/golang/mock/mockgen@v1.6.0
|
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
|
endif
|
||||||
|
|
||||||
## Show help documentation.
|
## Show help documentation.
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
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
|
||||||
|
|
|
@ -130,7 +130,7 @@ type AssetProcessorConfig struct {
|
||||||
|
|
||||||
// GoModule represents information from go.mod file.
|
// GoModule represents information from go.mod file.
|
||||||
type GoModule struct {
|
type GoModule struct {
|
||||||
Module string
|
Name string
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,19 +284,22 @@ func parseGoModule(pluginPath string) (*GoModule, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
goMod := &GoModule{}
|
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)
|
line = strings.TrimSpace(line)
|
||||||
|
|
||||||
// Parse module line
|
// Parse module line
|
||||||
if strings.HasPrefix(line, "module ") {
|
if remainder, found := strings.CutPrefix(line, "module "); found {
|
||||||
goMod.Module = strings.TrimSpace(strings.TrimPrefix(line, "module "))
|
goMod.Name = strings.TrimSpace(remainder)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse go version line
|
// Parse go version line
|
||||||
if strings.HasPrefix(line, "go ") {
|
if remainder, found := strings.CutPrefix(line, "go "); found {
|
||||||
goMod.Version = strings.TrimSpace(strings.TrimPrefix(line, "go "))
|
goMod.Version = strings.TrimSpace(remainder)
|
||||||
|
|
||||||
|
// We don't need to parse any further
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue