feat: use github.com/wlynxg/anet instead of net

See https://github.com/golang/go/issues/40569
This commit is contained in:
2024-05-02 09:40:55 +02:00
parent 2fbc7186c0
commit 6aec6da078
3 changed files with 8 additions and 25 deletions

View File

@ -3,8 +3,6 @@ package chromecast
import (
"context"
"net"
"regexp"
"strconv"
"strings"
"sync"
"time"
@ -15,6 +13,7 @@ import (
"github.com/barnybug/go-cast/log"
"github.com/hashicorp/mdns"
"github.com/pkg/errors"
"github.com/wlynxg/anet"
)
const (
@ -151,28 +150,11 @@ func (d *Discovery) listener(ctx context.Context) {
case d.found <- client:
case <-time.After(time.Second):
case <-ctx.Done():
break
return
}
}
}
func decodeDnsEntry(text string) string {
text = strings.Replace(text, `\.`, ".", -1)
text = strings.Replace(text, `\ `, " ", -1)
re := regexp.MustCompile(`([\\][0-9][0-9][0-9])`)
text = re.ReplaceAllStringFunc(text, func(source string) string {
i, err := strconv.Atoi(source[1:])
if err != nil {
return ""
}
return string([]byte{byte(i)})
})
return text
}
func decodeTxtRecord(txt string) map[string]string {
m := make(map[string]string)
@ -196,7 +178,7 @@ func isIPv6(ip net.IP) bool {
}
func findMulticastInterfaces(ctx context.Context) ([]net.Interface, error) {
ifaces, err := net.Interfaces()
ifaces, err := anet.Interfaces()
if err != nil {
return nil, nil
}
@ -223,7 +205,7 @@ func findMulticastInterfaces(ctx context.Context) ([]net.Interface, error) {
}
func retrieveSupportedProtocols(iface net.Interface) (bool, bool, error) {
adresses, err := iface.Addrs()
adresses, err := anet.InterfaceAddrsByInterface(&iface)
if err != nil {
return false, false, errors.WithStack(err)
}