feat(discovery): android compatibility

This commit is contained in:
2024-08-06 09:32:02 +02:00
parent 6842d4d88a
commit 33e16c8615
8 changed files with 725 additions and 80 deletions

View File

@ -5,25 +5,30 @@ import (
"encoding/json"
"fmt"
"os"
"time"
"forge.cadoles.com/cadoles/go-emlid/reach/discovery"
"github.com/pkg/errors"
)
func main() {
services, err := discovery.Watch(context.Background())
resolver := discovery.NewResolver()
found, err := resolver.Scan(context.Background(), 1*time.Second)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
for srv := range services {
for srv := range found {
data, err := json.MarshalIndent(struct {
Addr string `json:"addr"`
Name string `json:"name"`
Addr string `json:"addr"`
Name string `json:"name"`
Device string `json:"device"`
}{
Name: srv.Name,
Addr: fmt.Sprintf("%s:%d", srv.AddrV4.String(), srv.Port),
Name: srv.Name,
Addr: fmt.Sprintf("%s:%d", srv.AddrV4.String(), srv.Port),
Device: srv.Device,
}, "", " ")
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))