-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add helpers for unmarshal JSON object into Options map #9
Conversation
Hi, IMHO I don't think that sort of functionality belongs in the dhcp4 package as it near doubles the source size, on the oft chance that the user wants to store DHCP options, in that particular JSON format. However, I do think there is merit in having this code in a separate package, which imports the dhcp4 package for the Options type. That way those wanting the functionality can import your package along with my one. Thoughts? |
I like this idea (separate package or sub package) but Go doesn't allow to do this: How do I import Parent-package from Sub-package for method?:
|
Perhaps something like: Change object from dhcp4.Options to JSONOptions: And when finished (in the example) cast your JSONOptions to dhcp4.Options. |
Done. Usage: import "encoding/json"
import "github.com/krolaw/dhcp4"
import "github.com/krolaw/dhcp4/reflectDHCP"
...
var opt = dhcp4.Options{};
json.Unmarshal(strJSON, (*reflectDHCP.Options)(&opt)); |
Not wanting to have misled, but I imagined the separate package would have been called something like: That way it's your feature, your responsibility. I won't need to sign off or check improvements AND I can redirect requests for XML, TOML, bind, etc formats to their own packages that I also don't manage :-) |
New repo https://github.com/ZiroKyl/reflectDHCP
I understand: ZiroKyl@b05b5da#diff-23900ffffef263bf9082a906ba6c278aR371 |
Implements the json.Unmarshaler interface for DHCP Options map.
This adds simple way to init DHCP Options from JSON object. For example, read DHCP Options from JSON formatted config file.
P.S.
go test
also been implemented.