Enable golint part of #14756

pkg/broadcastwriter
pkg/graphdb
pkg/httputils
pkg/ioutils

Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Lei Jitang 2015-08-03 09:45:05 +08:00
parent fca8ba94b3
commit fcb8d8d48e
11 changed files with 60 additions and 32 deletions

View file

@ -53,7 +53,7 @@ func (r *multiReadSeeker) Seek(offset int64, whence int) (int64, error) {
}
if rdrOffset == s && i != len(r.readers)-1 {
idx += 1
idx++
rdrOffset = 0
}
r.pos = &pos{idx, rdrOffset}

View file

@ -23,6 +23,7 @@ func (r *readCloserWrapper) Close() error {
return r.closer()
}
// NewReadCloserWrapper returns a new io.ReadCloser.
func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser {
return &readCloserWrapper{
Reader: r,
@ -43,6 +44,7 @@ func (r *readerErrWrapper) Read(p []byte) (int, error) {
return n, err
}
// NewReaderErrWrapper returns a new io.Reader.
func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader {
return &readerErrWrapper{
reader: r,
@ -68,7 +70,8 @@ type bufReader struct {
maxReadDataReset int64
}
func NewBufReader(r io.Reader) *bufReader {
// NewBufReader returns a new bufReader.
func NewBufReader(r io.Reader) io.ReadCloser {
timeout := rand.New(rndSrc).Intn(120) + 180
reader := &bufReader{
@ -86,7 +89,8 @@ func NewBufReader(r io.Reader) *bufReader {
return reader
}
func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer *bytes.Buffer) *bufReader {
// NewBufReaderWithDrainbufAndBuffer returns a BufReader with drainBuffer and buffer.
func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer *bytes.Buffer) io.ReadCloser {
reader := &bufReader{
buf: buffer,
drainBuf: drainBuffer,
@ -210,6 +214,7 @@ func (r *bufReader) Read(p []byte) (n int, err error) {
}
}
// Close closes the bufReader
func (r *bufReader) Close() error {
closer, ok := r.reader.(io.ReadCloser)
if !ok {
@ -218,6 +223,7 @@ func (r *bufReader) Close() error {
return closer.Close()
}
// HashData returns the sha256 sum of src.
func HashData(src io.Reader) (string, error) {
h := sha256.New()
if _, err := io.Copy(h, src); err != nil {
@ -226,6 +232,8 @@ func HashData(src io.Reader) (string, error) {
return "sha256:" + hex.EncodeToString(h.Sum(nil)), nil
}
// OnEOFReader wraps a io.ReadCloser and a function
// the fuction will run at the end of file or close the file.
type OnEOFReader struct {
Rc io.ReadCloser
Fn func()
@ -239,6 +247,7 @@ func (r *OnEOFReader) Read(p []byte) (n int, err error) {
return
}
// Close closes the file and run the function.
func (r *OnEOFReader) Close() error {
err := r.Rc.Close()
r.runFunc()

View file

@ -6,6 +6,7 @@ import (
"sync"
)
// WriteFlusher wraps the Write and Flush operation.
type WriteFlusher struct {
sync.Mutex
w io.Writer
@ -30,12 +31,15 @@ func (wf *WriteFlusher) Flush() {
wf.flusher.Flush()
}
// Flushed returns the state of flushed.
// If it's flushed, return true, or else it return false.
func (wf *WriteFlusher) Flushed() bool {
wf.Lock()
defer wf.Unlock()
return wf.flushed
}
// NewWriteFlusher returns a new WriteFlusher.
func NewWriteFlusher(w io.Writer) *WriteFlusher {
var flusher http.Flusher
if f, ok := w.(http.Flusher); ok {

View file

@ -2,6 +2,7 @@ package ioutils
import "io"
// NopWriter represents a type which write operation is nop.
type NopWriter struct{}
func (*NopWriter) Write(buf []byte) (int, error) {
@ -14,12 +15,15 @@ type nopWriteCloser struct {
func (w *nopWriteCloser) Close() error { return nil }
// NopWriteCloser returns a nopWriteCloser.
func NopWriteCloser(w io.Writer) io.WriteCloser {
return &nopWriteCloser{w}
}
// NopFlusher represents a type which flush opetatin is nop.
type NopFlusher struct{}
// Flush is a nop operation.
func (f *NopFlusher) Flush() {}
type writeCloserWrapper struct {
@ -31,6 +35,7 @@ func (r *writeCloserWrapper) Close() error {
return r.closer()
}
// NewWriteCloserWrapper returns a new io.WriteCloser.
func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
return &writeCloserWrapper{
Writer: r,
@ -38,7 +43,7 @@ func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
}
}
// Wrap a concrete io.Writer and hold a count of the number
// WriteCounter wraps a concrete io.Writer and hold a count of the number
// of bytes written to the writer during a "session".
// This can be convenient when write return is masked
// (e.g., json.Encoder.Encode())
@ -47,6 +52,7 @@ type WriteCounter struct {
Writer io.Writer
}
// NewWriteCounter returns a new WriteCounter.
func NewWriteCounter(w io.Writer) *WriteCounter {
return &WriteCounter{
Writer: w,