From 032259baf192d2aed42c2be554e51bd87621f0d9 Mon Sep 17 00:00:00 2001 From: Jozef Kralik Date: Wed, 18 Oct 2023 06:40:15 +0000 Subject: [PATCH] Add a //go:build directive to support Go 1.18 --- udp/isRunninigInterface_1.18_test.go | 9 +++++++++ udp/isRunninigInterface_1.20_test.go | 9 +++++++++ udp/server_test.go | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 udp/isRunninigInterface_1.18_test.go create mode 100644 udp/isRunninigInterface_1.20_test.go diff --git a/udp/isRunninigInterface_1.18_test.go b/udp/isRunninigInterface_1.18_test.go new file mode 100644 index 00000000..28d462fb --- /dev/null +++ b/udp/isRunninigInterface_1.18_test.go @@ -0,0 +1,9 @@ +//go:build go1.18 || go1.19 + +package udp_test + +import "net" + +func isRunningInterface(net.Interface) bool { + return true +} diff --git a/udp/isRunninigInterface_1.20_test.go b/udp/isRunninigInterface_1.20_test.go new file mode 100644 index 00000000..ca5d6604 --- /dev/null +++ b/udp/isRunninigInterface_1.20_test.go @@ -0,0 +1,9 @@ +//go:build !go1.18 && !go1.19 + +package udp_test + +import "net" + +func isRunningInterface(i net.Interface) bool { + return i.Flags&net.FlagRunning == net.FlagRunning +} diff --git a/udp/server_test.go b/udp/server_test.go index 37f9f613..0ec3e22a 100644 --- a/udp/server_test.go +++ b/udp/server_test.go @@ -91,7 +91,7 @@ func TestServerDiscover(t *testing.T) { log.Printf("ifs:%v", ifs) var iface net.Interface for _, i := range ifs { - if i.Flags&net.FlagMulticast == net.FlagMulticast && i.Flags&net.FlagUp == net.FlagUp && i.Flags&net.FlagRunning == net.FlagRunning { + if i.Flags&net.FlagMulticast == net.FlagMulticast && i.Flags&net.FlagUp == net.FlagUp && isRunningInterface(i) { iface = i log.Printf("first available multicast if:%v", iface) break