2024-07-30 14:28:39 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2024-08-02 12:57:07 +02:00
|
|
|
"log/slog"
|
2024-07-30 14:28:39 +02:00
|
|
|
"os"
|
|
|
|
|
|
|
|
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
|
2024-08-02 12:57:07 +02:00
|
|
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
|
2024-07-30 14:28:39 +02:00
|
|
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
|
|
|
v1 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v1"
|
|
|
|
v2 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
host string = "192.168.42.1"
|
|
|
|
preferredProtocol string = string(v2.Identifier)
|
|
|
|
fallbackProtocol string = string(v1.Identifier)
|
2024-08-02 12:57:07 +02:00
|
|
|
rawLogLevel string = "ERROR"
|
2024-07-30 14:28:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-08-02 12:57:07 +02:00
|
|
|
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
|
2024-07-30 14:28:39 +02:00
|
|
|
flag.StringVar(&host, "host", host, "the reachrs module host")
|
|
|
|
flag.StringVar(&preferredProtocol, "preferred-protocol", preferredProtocol, "preferred-protocol")
|
|
|
|
flag.StringVar(&fallbackProtocol, "fallback-protocol", fallbackProtocol, "fallback-protocol")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2024-08-02 12:57:07 +02:00
|
|
|
logLevel, err := logger.ParseLevel(rawLogLevel)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.SetLogLoggerLevel(logLevel)
|
|
|
|
|
2024-07-30 14:28:39 +02:00
|
|
|
ctx := context.Background()
|
|
|
|
client := reach.NewClient(
|
|
|
|
host,
|
|
|
|
reach.WithPreferredProtocol(protocol.Identifier(preferredProtocol)),
|
|
|
|
reach.WithFallbackProtocol(protocol.Identifier(fallbackProtocol)),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := client.Connect(ctx); err != nil {
|
|
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err := client.Close(ctx); err != nil {
|
|
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
config, err := client.Configuration(ctx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.MarshalIndent(config, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(data))
|
|
|
|
}
|