Paul Hinze 8b5d4b8631
Update and address protobuf package deprecations
These changes address the following warning showing up on `go get`
operations:

    go: module github.com/golang/protobuf is deprecated: Use the
    "google.golang.org/protobuf" module instead.

All changes are made using the recommendations in the per-function
deprecation notices from the docs at
https://pkg.go.dev/github.com/golang/protobuf/ptypes
2022-06-08 11:51:19 -05:00

44 lines
1.2 KiB
Go

package logviewer
import (
"context"
"github.com/hashicorp/vagrant-plugin-sdk/component"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
)
// Viewer implements component.LogViewer over the server-side log stream endpoint.
//
// TODO(mitchellh): we should support some form of reconnection in the event of
// network errors.
type Viewer struct {
// Stream is the log stream client to use.
Stream vagrant_server.Vagrant_GetLogStreamClient
}
// NextLogBatch implements component.LogViewer
func (v *Viewer) NextLogBatch(ctx context.Context) ([]component.LogEvent, error) {
// Get the next batch. Note that we specifically do NOT buffer here because
// we want to provide the proper amount of backpressure and we expect our
// downstream caller to be calling these as quickly as possible.
batch, err := v.Stream.Recv()
if err != nil {
return nil, err
}
events := make([]component.LogEvent, len(batch.Lines))
for i, entry := range batch.Lines {
ts := entry.Timestamp.AsTime()
events[i] = component.LogEvent{
Partition: batch.InstanceId,
Timestamp: ts,
Message: entry.Line,
}
}
return events, nil
}
var _ component.LogViewer = (*Viewer)(nil)