41 lines
771 B
Go
41 lines
771 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"forge.cadoles.com/cadoles/go-emlid/reach/discovery"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func main() {
|
|
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 found {
|
|
data, err := json.MarshalIndent(struct {
|
|
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),
|
|
Device: srv.Device,
|
|
}, "", " ")
|
|
if err != nil {
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("%s\n", data)
|
|
}
|
|
}
|