*: reflow comments to 80 characters
This reformats the entire Metropolis codebase to have comments no longer
than 80 characters, implementing CR/66.
This has been done half manually, as we don't have a good integration
between commentwrap/Bazel, but that can be implemented if we decide to
go for this tool/limit.
Change-Id: If1fff0b093ef806f5dc00551c11506e8290379d0
diff --git a/metropolis/pkg/logbuffer/linebuffer.go b/metropolis/pkg/logbuffer/linebuffer.go
index 8048604..6fd9a62 100644
--- a/metropolis/pkg/logbuffer/linebuffer.go
+++ b/metropolis/pkg/logbuffer/linebuffer.go
@@ -25,7 +25,8 @@
apb "source.monogon.dev/metropolis/proto/api"
)
-// Line is a line stored in the log buffer - a string, that has been perhaps truncated (due to exceeded limits).
+// Line is a line stored in the log buffer - a string, that has been perhaps
+// truncated (due to exceeded limits).
type Line struct {
Data string
OriginalLength int
@@ -36,8 +37,8 @@
return l.OriginalLength > len(l.Data)
}
-// String returns the line with an ellipsis at the end (...) if the line has been truncated, or the original line
-// otherwise.
+// String returns the line with an ellipsis at the end (...) if the line has been
+// truncated, or the original line otherwise.
func (l *Line) String() string {
if l.Truncated() {
return l.Data + "..."
@@ -68,24 +69,27 @@
}, nil
}
-// LineBuffer is a io.WriteCloser that will call a given callback every time a line is completed.
+// LineBuffer is a io.WriteCloser that will call a given callback every time a line
+// is completed.
type LineBuffer struct {
maxLineLength int
cb LineBufferCallback
mu sync.Mutex
cur strings.Builder
- // length is the length of the line currently being written - this will continue to increase, even if the string
- // exceeds maxLineLength.
+ // length is the length of the line currently being written - this will continue to
+ // increase, even if the string exceeds maxLineLength.
length int
closed bool
}
-// LineBufferCallback is a callback that will get called any time the line is completed. The function must not cause another
-// write to the LineBuffer, or the program will deadlock.
+// LineBufferCallback is a callback that will get called any time the line is
+// completed. The function must not cause another write to the LineBuffer, or the
+// program will deadlock.
type LineBufferCallback func(*Line)
-// NewLineBuffer creates a new LineBuffer with a given line length limit and callback.
+// NewLineBuffer creates a new LineBuffer with a given line length limit and
+// callback.
func NewLineBuffer(maxLineLength int, cb LineBufferCallback) *LineBuffer {
return &LineBuffer{
maxLineLength: maxLineLength,
@@ -93,7 +97,8 @@
}
}
-// writeLimited writes to the internal buffer, making sure that its size does not exceed the maxLineLength.
+// writeLimited writes to the internal buffer, making sure that its size does not
+// exceed the maxLineLength.
func (l *LineBuffer) writeLimited(data []byte) {
l.length += len(data)
if l.cur.Len()+len(data) > l.maxLineLength {
@@ -144,8 +149,8 @@
return len(data), nil
}
-// Close will emit any leftover data in the buffer to the callback. Subsequent calls to Write will fail. Subsequent calls to Close
-// will also fail.
+// Close will emit any leftover data in the buffer to the callback. Subsequent
+// calls to Write will fail. Subsequent calls to Close will also fail.
func (l *LineBuffer) Close() error {
if l.closed {
return fmt.Errorf("already closed")
diff --git a/metropolis/pkg/logbuffer/logbuffer.go b/metropolis/pkg/logbuffer/logbuffer.go
index ce47816..cd18420 100644
--- a/metropolis/pkg/logbuffer/logbuffer.go
+++ b/metropolis/pkg/logbuffer/logbuffer.go
@@ -14,10 +14,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// Package logbuffer implements a fixed-size in-memory ring buffer for line-separated logs.
-// It implements io.Writer and splits the data into lines. The lines are kept in a ring where the
-// oldest are overwritten once it's full. It allows retrieval of the last n lines. There is a built-in
-// line length limit to bound the memory usage at maxLineLength * size.
+// Package logbuffer implements a fixed-size in-memory ring buffer for
+// line-separated logs. It implements io.Writer and splits the data into lines.
+// The lines are kept in a ring where the oldest are overwritten once it's
+// full. It allows retrieval of the last n lines. There is a built-in line
+// length limit to bound the memory usage at maxLineLength * size.
package logbuffer
import (
@@ -32,7 +33,8 @@
*LineBuffer
}
-// New creates a new LogBuffer with a given ringbuffer size and maximum line length.
+// New creates a new LogBuffer with a given ringbuffer size and maximum line
+// length.
func New(size, maxLineLength int) *LogBuffer {
lb := &LogBuffer{
content: make([]Line, size),
@@ -49,7 +51,8 @@
b.length++
}
-// capToContentLength caps the number of requested lines to what is actually available
+// capToContentLength caps the number of requested lines to what is actually
+// available
func (b *LogBuffer) capToContentLength(n int) int {
// If there aren't enough lines to read, reduce the request size
if n > b.length {
@@ -62,8 +65,9 @@
return n
}
-// ReadLines reads the last n lines from the buffer in chronological order. If n is bigger than the
-// ring buffer or the number of available lines only the number of stored lines are returned.
+// ReadLines reads the last n lines from the buffer in chronological order. If
+// n is bigger than the ring buffer or the number of available lines only the
+// number of stored lines are returned.
func (b *LogBuffer) ReadLines(n int) []Line {
b.mu.RLock()
defer b.mu.RUnlock()
@@ -78,13 +82,14 @@
return outArray
}
-// ReadLinesTruncated works exactly the same as ReadLines, but adds an ellipsis at the end of every
-// line that was truncated because it was over MaxLineLength
+// ReadLinesTruncated works exactly the same as ReadLines, but adds an ellipsis
+// at the end of every line that was truncated because it was over
+// MaxLineLength
func (b *LogBuffer) ReadLinesTruncated(n int, ellipsis string) []string {
b.mu.RLock()
defer b.mu.RUnlock()
- // This does not use ReadLines() to prevent excessive reference copying and associated GC pressure
- // since it could process a lot of lines.
+ // This does not use ReadLines() to prevent excessive reference copying and
+ // associated GC pressure since it could process a lot of lines.
n = b.capToContentLength(n)