-
Notifications
You must be signed in to change notification settings - Fork 136
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
Implement interface specification syntax #58
Conversation
1072328
to
0e613d4
Compare
} | ||
} | ||
|
||
func TestOnChangeCmd(t *testing.T) { |
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 think this TestOnChangeCmd
and TestHealthCheck
got moved to this file accidentally.
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.
We should add |
* state. */ | ||
if interfaceIPsErr != nil && len(interfaceIPs) > 0 { | ||
log.Printf("We had a problem reading information about some network "+ | ||
"interfaces. If everything works, it is safe to ignore this"+ |
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.
incredibly tiny nitpick: you'll want a space here after "this"
New structs that implement the interface: - indexInterfaceSpec : matches eth[0] - inetInterfaceSpec : matches inet6 and eth0:inet6, eth0 - cidrInterfaceSpec : matches 10.0.0.0/16 and fdc6:238c:c4bc::/48
// Interface Spec | ||
type interfaceSpec interface { | ||
Match(index int, iip interfaceIP) bool | ||
String() 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.
As far as I can tell this is an unused method.
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.
Isn't String() used implicitly when doing fmt.Printf ? https://golang.org/pkg/fmt/
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.
Yeah, but we only care about that if the fmt
is user-visible, in which case we could just pass someSpecInstance.Spec
to the formatter.
@tgross Most of the new comments relate to the String() method (and inheriting it through baseInterfaceSpec). I am still new to go - so I'm probably coding Java in golang instead of doing something more idiomatic. If you want me to cut out String() completely, let me know. |
- Remove String() from interfaceSpec - Put Spec in each implementation struct - parseInterfaceSpec can now return nil on error
e30c581
to
3379712
Compare
Honestly, if this were a non-technical-user-facing application, I'd say it'd be the right way to go because you're going to want to return pretty-printed errors to the user. But for Containerbuddy's audience, returning the default struct formatting by default is probably a better approach when it comes to debugging and logging -- this way the user gets whatever fields in the struct that we've managed to construct at that point instead of just the |
Ok, this is good-to-go. Nice work, @justenwalker |
Implement interface specification syntax
For #53
Changes
interfaces
optionInterface Specification
eth0
: Match the first IPv4 address oneth0
(alias foreth0:inet
)eth0:inet6
: Match the first IPv6 address oneth0
eth0[1]
: Match the 2nd IP address oneth0
10.0.0.0/16
: Match the first IP that is contained within the IP Networkfdc6:238c:c4bc::/48
: Match the first IP that is contained within the IPv6 Networkinet
: Match the first IPv4 Address (excluding127.0.0.0/8
)inet6
: Match the first IPv6 Address (excluding::1/128
)Stable Sorting
Interfaces and their IP addresses are ordered alphabetically by interface name, then by IP address (lexicographically by bytes).