Merge pull request #107 from aanm/pretty-result
added the String method to Result type
This commit is contained in:
commit
224ac412da
@ -16,6 +16,7 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
@ -75,6 +76,20 @@ func (r *Result) Print() error {
|
|||||||
return prettyPrint(r)
|
return prettyPrint(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a formatted string in the form of "[IP4: $1,][ IP6: $2,] DNS: $3" where
|
||||||
|
// $1 represents the receiver's IPv4, $2 represents the receiver's IPv6 and $3 the
|
||||||
|
// receiver's DNS. If $1 or $2 are nil, they won't be present in the returned string.
|
||||||
|
func (r *Result) String() string {
|
||||||
|
var str string
|
||||||
|
if r.IP4 != nil {
|
||||||
|
str = fmt.Sprintf("IP4:%+v, ", *r.IP4)
|
||||||
|
}
|
||||||
|
if r.IP6 != nil {
|
||||||
|
str += fmt.Sprintf("IP6:%+v, ", *r.IP6)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%sDNS:%+v", str, r.DNS)
|
||||||
|
}
|
||||||
|
|
||||||
// IPConfig contains values necessary to configure an interface
|
// IPConfig contains values necessary to configure an interface
|
||||||
type IPConfig struct {
|
type IPConfig struct {
|
||||||
IP net.IPNet
|
IP net.IPNet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user