-
Notifications
You must be signed in to change notification settings - Fork 4
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
Possibility to dump tree as json #1
Conversation
Pull Request Test Coverage Report for Build 7800491566Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
@mieczkowski thanks for contribution. Since you didn't open an issue before, I updated the main branch already by accident. Please rebase your PR on it. ... and by reading the code (well done!) I've just some minor remarks:
just my five cents |
Good catch with errors handling - I've simplified code. However I can not test one error check, because there is no chance to simulate this error, except some I/O errors inside buf, err := json.Marshal(result)
if err != nil {
return nil, err
} Please consider leaving DumpList as public function. In my case I have list of subnets in DB (flat list). I need to rebuild tree after every operation on this with some validations, and:
Without this method I need to marshal json and parse it into map[string] . Unnecessary waste of resources and without it I will end up with fork - and I don't want that ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see my inline comment to DumpList
jsonify.go
Outdated
@@ -44,40 +37,28 @@ func (t *Table[V]) MarshalJSON() ([]byte, error) { | |||
} | |||
|
|||
// DumpList dumps ipv4 od ipv6 tree into list of roots and their children |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still a typo in this public docstring and a missing dot at end of line. If this method has to be public, please invest more time to find a clear description or spend an extra test or maybe a dumplist_example_test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed both docstrings.
I don't think that we need separated tests for DumpList. It will be duplicate of json tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for DumpList was not meant for testing, just to better explain the public method, but I can live without or add it myself later.
Two more small remarks:
- public type ListElement needs a docstring.
- please rename field Cidr to CIDR, for golang naming convention, like HTTP and not Http
Regards
Charly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
What do you think about the following naming: type DumpListElement[V any] struct {}
func (t *Table[V]) DumpList(is4 bool) []DumpListElement[V] background: the type only deals with dumping and marshaling, nothing with the real bart-Table algo. |
I vote for |
merged, thanks for contribution |
Hello,
I need possibility to dump tree to list of records (to store in DB for example), so I've added two methods:
MarshalJSON
to marshal tree (separated ipv4 and ipv6 keys) to json.DumpList
to build custom json struct, use for example in database storage, or for debug purpose.Test data is taken from
stringify_test.go
.