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

[question] Why can't Encoder check and call fmt.Stringer.String() on element automatically? #196

Open
howellzhu opened this issue Dec 1, 2022 · 1 comment
Labels

Comments

@howellzhu
Copy link

howellzhu commented Dec 1, 2022

Why can't Encoder directly determine whether an element implements an interface (such as fmt.Stringer or encoding.TextMarshaler) and actively call its interface to implement Encode()?

After all, Decode already does that (using encoding.TextUnmrshaler interface).

@jaitaiwan
Copy link
Member

I can look at this again, but from my understanding, go doesn't have a specific way to check if a type implements an interface. We'd have to do reflection and see if a method with a particular name existed. I'm not sure what the benefit of doing this would actually be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants