ocket8888 commented on a change in pull request #4916:
URL: https://github.com/apache/trafficcontrol/pull/4916#discussion_r466749336
##########
File path: lib/go-tc/servers.go
##########
@@ -97,6 +99,30 @@ type ServerInterfaceInfo struct {
Name string `json:"name" db:"name"`
}
+// GetDefaultAddress returns the IPv4 and IPv6 service addresses of the
interface.
+func (i *ServerInterfaceInfo) GetDefaultAddress() (string, string) {
+ var ipv4 string
+ var ipv6 string
+ for _, ip := range i.IPAddresses {
+ if ip.ServiceAddress {
+ address, _, err := net.ParseCIDR(ip.Address)
+ if err != nil || address == nil {
+ continue
Review comment:
nah. I generally consider importing the logger into the tc, utils, or
rfc packages bad form, since they're just libraries, and should be able to run
their code in situations where logging is impossible, not set up, or doesn't
even make sense. So if anything, it should just return the error and make the
caller deal with it.
But also, I didn't write this method. I just changed the receiver; we had
two separate, equivalent definitions of server interfaces. The other one was in
`traffic_router.go`. I deleted that one and moved this method to its new, more
appropriate location. So I don't really wanna change it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]