diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-10-12 07:18:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 13:18:26 +0800 |
commit | 0e57ff7eee4ac71d923f970d15889ad4d50f97a9 (patch) | |
tree | e5a92c55af5366924bd40ae14b4bf12842239193 /modules/issue/template | |
parent | e84558b0931309cf1f4f2767bc47296483b9b3e1 (diff) | |
download | gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.tar.gz gitea-0e57ff7eee4ac71d923f970d15889ad4d50f97a9.zip |
Add generic set type (#21408)
This PR adds a generic set type to get rid of maps used as sets.
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'modules/issue/template')
-rw-r--r-- | modules/issue/template/template.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go index a4c0fb5aa6..3b33852cb5 100644 --- a/modules/issue/template/template.go +++ b/modules/issue/template/template.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" + "code.gitea.io/gitea/modules/container" api "code.gitea.io/gitea/modules/structs" "gitea.com/go-chi/binding" @@ -43,7 +44,7 @@ func validateYaml(template *api.IssueTemplate) error { if len(template.Fields) == 0 { return fmt.Errorf("'body' is required") } - ids := map[string]struct{}{} + ids := make(container.Set[string]) for idx, field := range template.Fields { if err := validateID(field, idx, ids); err != nil { return err @@ -125,7 +126,7 @@ func validateRequired(field *api.IssueFormField, idx int) error { return validateBoolItem(newErrorPosition(idx, field.Type), field.Validations, "required") } -func validateID(field *api.IssueFormField, idx int, ids map[string]struct{}) error { +func validateID(field *api.IssueFormField, idx int, ids container.Set[string]) error { if field.Type == api.IssueFormFieldTypeMarkdown { // The ID is not required for a markdown field return nil @@ -139,10 +140,9 @@ func validateID(field *api.IssueFormField, idx int, ids map[string]struct{}) err if binding.AlphaDashPattern.MatchString(field.ID) { return position.Errorf("'id' should contain only alphanumeric, '-' and '_'") } - if _, ok := ids[field.ID]; ok { + if !ids.Add(field.ID) { return position.Errorf("'id' should be unique") } - ids[field.ID] = struct{}{} return nil } |