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 net/route parse, also add util lib Pars… #508
Conversation
…eIpv4FromHexString function - sansna Signed-off-by: sansna <1185280650@qq.com>
passed tests |
internal/util/parse.go
Outdated
@@ -110,3 +112,20 @@ func ParseBool(b string) *bool { | |||
} | |||
return &truth | |||
} | |||
|
|||
// Transforms uint32 to ipv4 representation | |||
func uint322Ipv4(n uint32) string { |
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.
let's rename this to uint32ToIPv4.
You can also probably shorten the body to return binary.LittleEndian.PutUint32(net.IP{}, uint32(n)).String()
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.
seems not possible to shorten its body like your said way, happy to rename though.
internal/util/parse.go
Outdated
} | ||
|
||
// Input: "00000000" | ||
// output: "0.0.0.0" |
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.
Rename function and convert the comemnt to a proper doc string:
// ParseIPv4FromHexString takes a string in format ....
net_route.go
Outdated
} | ||
|
||
hexss := make([]string, 0, 3) | ||
hexss = append(hexss, fields[1], fields[2], fields[7]) |
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.
You should be able to do hexss := []string{fields[1], fields[2], fields[7]} with
make()` before. Same below for uss.
In general though, why don't you assing right away e.g routeline.Destination = util.ParseHexUint64(fields[1])
? No need to these temp slices here.
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 found no singular form of parse in util lib, so i tried to use the plural form, maybe its better to create these method myself
net_route.go
Outdated
return nil, err | ||
} | ||
// hex | ||
routeline.Destination = uint32(*hex[0]) |
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.
Just create routeline here and assing everything, e.g:
routeline := &NetRouteLine{
Ifrace: ...,
Destination: ...
...
Congrats to your first contribution! I have a few comments. Lemme know if you need any clarification! |
…- sansna Signed-off-by: sansna <1185280650@qq.com>
any advices, welcome |
Look at the linter errors, still need toget fixed. |
definitely, recently i got a job, don't have much time, sorry and thanks. |
85ac652
to
4425768
Compare
Signed-off-by: sansna <1185280650@qq.com>
please check again, thanks for your help |
Co-authored-by: Ben Kochie <superq@gmail.com> Signed-off-by: 三叁 <1185280650@qq.com>
Co-authored-by: Ben Kochie <superq@gmail.com> Signed-off-by: 三叁 <1185280650@qq.com>
Co-authored-by: Ben Kochie <superq@gmail.com> Signed-off-by: 三叁 <1185280650@qq.com>
Signed-off-by: sansna <1185280650@qq.com>
Signed-off-by: sansna <1185280650@qq.com>
thank you for your work, removed these code, plz check again @discordianfish |
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.
Great
first time to contribute to this repo, might
adds trivial parse of file net/route.
@pgier