Skip to content

Commit 44c231a

Browse files
ChBLAKimNorgaard
authored andcommitted
fix: review comments
1 parent a74a92d commit 44c231a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

xstructs/map.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (h *handler) handle(obj any) any {
114114
}
115115

116116
// handleStruct handles the conversion of a struct to a map[string]any.
117-
// It uses the "json" and "yaml" tags to determine the key names.
117+
// It uses the tags from the handler to determine the key names.
118118
func (h *handler) handleStruct(obj any) any {
119119
res := map[string]any{}
120120
val := reflect.ValueOf(obj)
@@ -222,16 +222,16 @@ func (h *handler) handleSlice(obj any) any {
222222
}
223223

224224
// getTag retrieves the tag name and options from a struct field.
225-
// It checks for the "json" and "yaml" tags in that order.
225+
// It checks the tags provided by the handler one by one.
226226
// If one tag is empty, it will return the other tag.
227-
// If both tags are empty, it returns an empty string and an empty slice.
227+
// If all tags are empty, it returns an error.
228228
func (h *handler) getTag(field reflect.StructField) (*tagWrapper, error) {
229229
for _, category := range h.tags {
230230
if tag := field.Tag.Get(category); tag != "" {
231231
splitTag := strings.Split(tag, ",")
232232
// Test if tag is solitary comma, i.e. `json:","`
233233
if splitTag[0] == "" && len(splitTag[1]) == 0 {
234-
return nil, fmt.Errorf("no tag of %s found for field %s", strings.Join(h.tags, ", "), field.Name)
234+
continue
235235
}
236236
return &tagWrapper{
237237
Name: splitTag[0],

0 commit comments

Comments
 (0)