Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handles any with RawValue #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

juliens
Copy link
Member

@juliens juliens commented Jan 17, 2024

This PR handles field any as RawValue.

it means that if you have for example something like

"foo.bar.baz"="fuu"
"foo.bar.huu"="hii"

and you try to handle it with a struct like

struct {
  foo any
}

This will do something like this:

{
   foo: map[string]any{
      "bar": map[string]any{
         "baz": "fuu",
         "huu": "hii",
      } 
   }
}

@juliens juliens added kind/enhancement a new or improved feature. status/2-needs-review labels Jan 17, 2024
@ldez ldez changed the title Handles any with RawValue feat: handles any with RawValue Jan 17, 2024
@ldez ldez self-requested a review January 17, 2024 16:21
Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflect.Interface is the kind used for the interfaces not only for any.

https://go.dev/play/p/gAEcY1vxauO

The real type used to fill an interface's field is not guessable.

The PR should either add tests about the interfaces (and different types) or document the limitations (and be sure that the problem produces a clear error).
The title and the description should also be updated.

In which context do you need to use a field any or an Interface?

@juliens
Copy link
Member Author

juliens commented Jan 22, 2024

I need to have any in the context where I don't know the real struct behind the data. In this context, I think that we were using map[string]interface{} but with this, it's not possible to put a string directly in this field.

To seperate any and real interface, may be I can use NumMethod?

https://go.dev/play/p/Jt7nSJ6veOO

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

Successfully merging this pull request may close these issues.

2 participants