fix: protocol v1
This commit is contained in:
35
cmd/discover/main.go
Normal file
35
cmd/discover/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user