goharbor / goharbor/harbor-cli
[refactor]: Extract regular expressions in pkg/utils to package scope
- Dominant language
- Go
- Stars
- 163
- Forks
- 211
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
## Problem
In `pkg/utils/helper.go`, several validation functions (like `ValidateEmail`, `ValidatePassword`, `ValidateProjectName`) currently compile regular expressions dynamically inside the function body using `regexp.MustCompile` or `regexp.MatchString`.
## Proposed Solution
Refactor the validation helpers so that the regular expressions are compiled once at the package scope (using a `var (...)` block). The functions will then reuse these precompiled variables. This is a minor code-quality cleanup that aligns the code with idiomatic Go practices and avoids unnecessary runtime recompilation.
## Alternatives Considered
N/A - This is a standard Go best practice for maintainability.
## Additional Context
I have already implemented this refactor, formatted the code with `gofmt`, and verified that all existing tests in `pkg/utils/helper_test.go` still pass perfectly without any behavior changes. I will open a PR shortly!
Contributor guide
Assessment
This issue has not been assessed yet.