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

How to ignore / bypass a field in a struct which I don't own / no control? #344

Open
tigerinus opened this issue Nov 14, 2023 · 1 comment

Comments

@tigerinus
Copy link

Hello,

I need to decode the a JSON supposed to be the type (ProxyTransport) from the frp project:

https://github.com/fatedier/frp/blob/v0.52.3/pkg/config/v1/proxy.go#L40

Its field BandwidthLimit is expected to be of type types.BandwidthQuantity.

But the actual value is an empty string ""

I don't own this project. I don't want to clone the struct and keep maintaining it.

Is there a way to bypass this field so the rest of the struct can be decoded?

Thanks!

@rashmi-tondare
Copy link

Did you try creating a custom DecoderConfig with a DecodeHookFuncValue? You could check the source type and return a default value for this specific field, for all other fields just return the source value directly.

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

No branches or pull requests

2 participants