go-emlid/cmd/discover/main.go

36 lines
654 B
Go

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