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:
@@ -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