stretchr/objx

Unable to select map key with dot

cretz opened this issue ยท 8 comments

cretz commented

If I have a map where the keys may be domain names and the values are some object, how do I select a field on the value for key "google.com" via Get?

Get("google.com")should work. Please provide a failing test case, if it doesn't.

cretz commented

I was more hoping Get("domains[google.com].hostname"). I can provide a test case if necessary. Basically, there is no way to escape special chars in the selector parser that I see.

A test case would be great!

cretz commented

I see. What would be your suggestion to fix this? Escape with \.?

geseq commented

One option would be to make the . and [] interchangeable for maps. So rather than escape separately, [] could be used as the accessor.

That is:

Get("a.b") == Get("a[b]")

I like this idea. Are you interested in implementing it?

geseq commented

Yeah, I'll work on it.