diff --git a/common/utils.go b/common/utils.go new file mode 100644 index 00000000..a3c372b2 --- /dev/null +++ b/common/utils.go @@ -0,0 +1,8 @@ +package common + +func OnOff(b bool) string { + if b { + return "on" + } + return "off" +} diff --git a/proxy/proxy.go b/proxy/proxy.go index 67f5b87e..de932baa 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -119,16 +119,8 @@ func (proxy *Proxy) Status() string { default: fmt.Fprintln(&buf, "TLS off") } - if proxy.WithDNS { - fmt.Fprintln(&buf, "DNS on") - } else { - fmt.Fprintln(&buf, "DNS off") - } - if proxy.WithIPAM { - fmt.Fprintln(&buf, "IPAM on") - } else { - fmt.Fprintln(&buf, "IPAM off") - } + fmt.Fprintln(&buf, "DNS", OnOff(proxy.WithDNS)) + fmt.Fprintln(&buf, "IPAM", OnOff(proxy.WithIPAM)) return buf.String() } diff --git a/router/router.go b/router/router.go index 15699205..afe80ad2 100644 --- a/router/router.go +++ b/router/router.go @@ -11,6 +11,7 @@ import ( "time" "code.google.com/p/gopacket/layers" + . "github.com/weaveworks/weave/common" ) const ( @@ -112,13 +113,9 @@ func (router *Router) UsingPassword() bool { } func (router *Router) Status() string { - encryption := "off" - if router.UsingPassword() { - encryption = "on" - } var buf bytes.Buffer fmt.Fprintln(&buf, "Our name is", router.Ourself) - fmt.Fprintln(&buf, "Encryption", encryption) + fmt.Fprintln(&buf, "Encryption", OnOff(router.UsingPassword())) fmt.Fprintln(&buf, "Sniffing traffic on", router.Iface) fmt.Fprintf(&buf, "MACs:\n%s", router.Macs) fmt.Fprintf(&buf, "Peers:\n%s", router.Peers)