mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 06:57:31 +00:00
client/local: use an iterator to stream bus events (#16269)
This means the caller does not have to remember to close the reader, and avoids having to duplicate the logic to decode JSON into events. Updates #15160 Change-Id: I20186fabb02f72522f61d5908c4cc80b86b8936b Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
@@ -157,7 +157,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
|
||||
💣 tailscale.com/util/deephash from tailscale.com/util/syspolicy/setting
|
||||
L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics
|
||||
tailscale.com/util/dnsname from tailscale.com/hostinfo+
|
||||
tailscale.com/util/eventbus from tailscale.com/net/netmon
|
||||
tailscale.com/util/eventbus from tailscale.com/net/netmon+
|
||||
💣 tailscale.com/util/hashx from tailscale.com/util/deephash
|
||||
tailscale.com/util/httpm from tailscale.com/client/tailscale
|
||||
tailscale.com/util/lineiter from tailscale.com/hostinfo+
|
||||
|
@@ -791,21 +791,14 @@ func runDaemonLogs(ctx context.Context, args []string) error {
|
||||
}
|
||||
|
||||
func runDaemonBusEvents(ctx context.Context, args []string) error {
|
||||
logs, err := localClient.StreamBusEvents(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer logs.Close()
|
||||
d := json.NewDecoder(bufio.NewReader(logs))
|
||||
for {
|
||||
var line eventbus.DebugEvent
|
||||
err := d.Decode(&line)
|
||||
for line, err := range localClient.StreamBusEvents(ctx) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("[%d][%q][from: %q][to: %q] %s\n", line.Count, line.Type,
|
||||
line.From, line.To, line.Event)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var metricsArgs struct {
|
||||
|
Reference in New Issue
Block a user