feat: goctl model Add a new method hasField (#5484)

This commit is contained in:
fyyang
2026-03-22 14:26:56 +08:00
committed by GitHub
parent 004995f06a
commit 9a6447ab5c
8 changed files with 193 additions and 11 deletions

View File

@@ -94,3 +94,16 @@ func Update() error {
return pathx.InitTemplates(category, templates)
}
// hasField returns a function that checks if a field exists in the table.
// It uses a pre-built map for O(1) lookup performance.
func hasField(table Table) func(string) bool {
fieldSet := make(map[string]struct{}, len(table.Fields))
for _, field := range table.Fields {
fieldSet[field.NameOriginal] = struct{}{}
}
return func(f string) bool {
_, ok := fieldSet[f]
return ok
}
}