Skip to content

Commit

Permalink
fix tag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
alovak committed Oct 25, 2024
1 parent 938552f commit ec4d932
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions field/index_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package field
import (
"reflect"
"regexp"
"slices"
"strconv"
"strings"
)
Expand Down Expand Up @@ -71,13 +72,13 @@ func NewIndexTag(field reflect.StructField) IndexTag {
}
}

type tagOptions string
type tagOptions []string

// parseTag splits a struct field's index tag into its id and
// comma-separated options.
func parseTag(tag string) (string, tagOptions) {
tag, opt, _ := strings.Cut(tag, ",")
return tag, tagOptions(opt)
return tag, tagOptions(strings.Split(opt, ","))
}

// Contains reports whether a comma-separated list of options
Expand All @@ -87,13 +88,6 @@ func (o tagOptions) Contains(optionName string) bool {
if len(o) == 0 {
return false
}
s := string(o)
for s != "" {
var name string
name, s, _ = strings.Cut(s, ",")
if name == optionName {
return true
}
}
return false

return slices.Contains(o, optionName)
}

0 comments on commit ec4d932

Please sign in to comment.