Skip to content

Conversation

sattellite
Copy link
Contributor

@sattellite sattellite commented Aug 18, 2025

I caught trouble when some fields in my structs have names that contains more then one uppercase letter. I fixed this trouble.

type A struct {
  B struct {
    C []struct{
      ID       int    // previous m2s searches for an "Id"
      UserName string // previous m2s searches for an "Username"
    }
  }
}

Now the tag name is respected into account in the structures inside the slice.

@cristaloleg
Copy link
Member

Hm, interesting

@sattellite
Copy link
Contributor Author

At first, I couldn't figure out what the problem was when my config was loading. I thought the problem was in the parent library for parsing toml itself. But after studying the code, I came to the conclusion that the problem lies in aconfig itself. For some reason, the m2s method uses the strings.Title(deprecated) to search for fields only in the format when the first letter is uppercase. And field names that are idiomatic for Go are ignored, such as ID (not Id). Field tags are also ignored, which makes it useless to specify them for structures in slices. I was added processing of tags to correctly select the field of structure for filling. But since at the time of filling it is unknown which decoder the data came from, I use a loop of connected decoders.

@sattellite
Copy link
Contributor Author

@cristaloleg hi, can you do a review for my pull request, please? I am ready to answer any questions you may have about the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants