Pārlūkot izejas kodu

Merge pull request #15013 from coolljt0725/14756_enbale_golint_1

Enable golint, part of #14756
Brian Goff 10 gadi atpakaļ
vecāks
revīzija
dce1488ae5

+ 4 - 0
hack/make/validate-lint

@@ -37,10 +37,14 @@ packages=(
 	graph
 	image
 	integration-cli
+	pkg/broadcastwriter
 	pkg/chrootarchive
 	pkg/directory
 	pkg/fileutils
+	pkg/graphdb
 	pkg/homedir
+	pkg/httputils
+	pkg/ioutils
 	pkg/listenbuffer
 	pkg/mflag
 	pkg/mflag/example

+ 1 - 0
pkg/broadcastwriter/broadcastwriter.go

@@ -44,6 +44,7 @@ func (w *BroadcastWriter) Clean() error {
 	return nil
 }
 
+// New creates a new BroadcastWriter.
 func New() *BroadcastWriter {
 	return &BroadcastWriter{
 		writers: make(map[io.WriteCloser]struct{}),

+ 3 - 1
pkg/graphdb/conn_sqlite3_unix.go

@@ -2,4 +2,6 @@
 
 package graphdb
 
-import _ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
+import (
+	_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
+)

+ 3 - 1
pkg/graphdb/conn_sqlite3_windows.go

@@ -2,4 +2,6 @@
 
 package graphdb
 
-import _ "github.com/mattn/go-sqlite3" // registers sqlite
+import (
+	_ "github.com/mattn/go-sqlite3" // registers sqlite
+)

+ 1 - 0
pkg/graphdb/conn_unsupported.go

@@ -2,6 +2,7 @@
 
 package graphdb
 
+// NewSqliteConn return a new sqlite connection.
 func NewSqliteConn(root string) (*Database, error) {
 	panic("Not implemented")
 }

+ 23 - 22
pkg/graphdb/graphdb.go

@@ -29,28 +29,28 @@ const (
     `
 )
 
-// Entity with a unique id
+// Entity with a unique id.
 type Entity struct {
 	id string
 }
 
-// An Edge connects two entities together
+// An Edge connects two entities together.
 type Edge struct {
 	EntityID string
 	Name     string
 	ParentID string
 }
 
-// Entities stores the list of entities
+// Entities stores the list of entities.
 type Entities map[string]*Entity
 
-// Edges stores the relationships between entities
+// Edges stores the relationships between entities.
 type Edges []*Edge
 
-// WalkFunc is a function invoked to process an individual entity
+// WalkFunc is a function invoked to process an individual entity.
 type WalkFunc func(fullPath string, entity *Entity) error
 
-// Database is a graph database for storing entities and their relationships
+// Database is a graph database for storing entities and their relationships.
 type Database struct {
 	conn *sql.DB
 	mux  sync.RWMutex
@@ -80,7 +80,7 @@ func IsNonUniqueNameError(err error) bool {
 	return false
 }
 
-// NewDatabase creates a new graph database initialized with a root entity
+// NewDatabase creates a new graph database initialized with a root entity.
 func NewDatabase(conn *sql.DB) (*Database, error) {
 	if conn == nil {
 		return nil, fmt.Errorf("Database connection cannot be nil")
@@ -130,12 +130,12 @@ func NewDatabase(conn *sql.DB) (*Database, error) {
 	return db, nil
 }
 
-// Close the underlying connection to the database
+// Close the underlying connection to the database.
 func (db *Database) Close() error {
 	return db.conn.Close()
 }
 
-// Set the entity id for a given path
+// Set the entity id for a given path.
 func (db *Database) Set(fullPath, id string) (*Entity, error) {
 	db.mux.Lock()
 	defer db.mux.Unlock()
@@ -171,7 +171,7 @@ func (db *Database) Set(fullPath, id string) (*Entity, error) {
 	return e, nil
 }
 
-// Exists returns true if a name already exists in the database
+// Exists returns true if a name already exists in the database.
 func (db *Database) Exists(name string) bool {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -198,14 +198,14 @@ func (db *Database) setEdge(parentPath, name string, e *Entity, tx *sql.Tx) erro
 	return nil
 }
 
-// RootEntity returns the root "/" entity for the database
+// RootEntity returns the root "/" entity for the database.
 func (db *Database) RootEntity() *Entity {
 	return &Entity{
 		id: "0",
 	}
 }
 
-// Get returns the entity for a given path
+// Get returns the entity for a given path.
 func (db *Database) Get(name string) *Entity {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -242,8 +242,8 @@ func (db *Database) get(name string) (*Entity, error) {
 
 }
 
-// List all entities by from the name
-// The key will be the full path of the entity
+// List all entities by from the name.
+// The key will be the full path of the entity.
 func (db *Database) List(name string, depth int) Entities {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -282,7 +282,7 @@ func (db *Database) Walk(name string, walkFunc WalkFunc, depth int) error {
 	return nil
 }
 
-// Children returns the children of the specified entity
+// Children returns the children of the specified entity.
 func (db *Database) Children(name string, depth int) ([]WalkMeta, error) {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -295,7 +295,7 @@ func (db *Database) Children(name string, depth int) ([]WalkMeta, error) {
 	return db.children(e, name, depth, nil)
 }
 
-// Parents returns the parents of a specified entity
+// Parents returns the parents of a specified entity.
 func (db *Database) Parents(name string) ([]string, error) {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -307,7 +307,7 @@ func (db *Database) Parents(name string) ([]string, error) {
 	return db.parents(e)
 }
 
-// Refs returns the refrence count for a specified id
+// Refs returns the refrence count for a specified id.
 func (db *Database) Refs(id string) int {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -319,7 +319,7 @@ func (db *Database) Refs(id string) int {
 	return count
 }
 
-// RefPaths returns all the id's path references
+// RefPaths returns all the id's path references.
 func (db *Database) RefPaths(id string) Edges {
 	db.mux.RLock()
 	defer db.mux.RUnlock()
@@ -347,7 +347,7 @@ func (db *Database) RefPaths(id string) Edges {
 	return refs
 }
 
-// Delete the reference to an entity at a given path
+// Delete the reference to an entity at a given path.
 func (db *Database) Delete(name string) error {
 	db.mux.Lock()
 	defer db.mux.Unlock()
@@ -446,6 +446,7 @@ func (db *Database) Rename(currentName, newName string) error {
 	return nil
 }
 
+// WalkMeta stores the walk metadata.
 type WalkMeta struct {
 	Parent   *Entity
 	Entity   *Entity
@@ -522,7 +523,7 @@ func (db *Database) parents(e *Entity) (parents []string, err error) {
 	return parents, nil
 }
 
-// Return the entity based on the parent path and name
+// Return the entity based on the parent path and name.
 func (db *Database) child(parent *Entity, name string) *Entity {
 	var id string
 	if err := db.conn.QueryRow("SELECT entity_id FROM edge WHERE parent_id = ? AND name = ?;", parent.id, name).Scan(&id); err != nil {
@@ -531,12 +532,12 @@ func (db *Database) child(parent *Entity, name string) *Entity {
 	return &Entity{id}
 }
 
-// ID returns the id used to reference this entity
+// ID returns the id used to reference this entity.
 func (e *Entity) ID() string {
 	return e.id
 }
 
-// Paths returns the paths sorted by depth
+// Paths returns the paths sorted by depth.
 func (e Entities) Paths() []string {
 	out := make([]string, len(e))
 	var i int

+ 5 - 4
pkg/httputils/httputils.go

@@ -10,7 +10,7 @@ import (
 	"github.com/docker/docker/pkg/jsonmessage"
 )
 
-// Download requests a given URL and returns an io.Reader
+// Download requests a given URL and returns an io.Reader.
 func Download(url string) (resp *http.Response, err error) {
 	if resp, err = http.Get(url); err != nil {
 		return nil, err
@@ -21,7 +21,7 @@ func Download(url string) (resp *http.Response, err error) {
 	return resp, nil
 }
 
-// NewHTTPRequestError returns a JSON response error
+// NewHTTPRequestError returns a JSON response error.
 func NewHTTPRequestError(msg string, res *http.Response) error {
 	return &jsonmessage.JSONError{
 		Message: msg,
@@ -29,14 +29,15 @@ func NewHTTPRequestError(msg string, res *http.Response) error {
 	}
 }
 
+// ServerHeader contains the server information.
 type ServerHeader struct {
 	App string // docker
 	Ver string // 1.8.0-dev
 	OS  string // windows or linux
 }
 
-// parseServerHeader extracts pieces from am HTTP server header
-// which is in the format "docker/version (os)" eg docker/1.8.0-dev (windows)
+// ParseServerHeader extracts pieces from an HTTP server header
+// which is in the format "docker/version (os)" eg docker/1.8.0-dev (windows).
 func ParseServerHeader(hdr string) (*ServerHeader, error) {
 	re := regexp.MustCompile(`.*\((.+)\).*$`)
 	r := &ServerHeader{}

+ 1 - 0
pkg/httputils/mimetype.go

@@ -5,6 +5,7 @@ import (
 	"net/http"
 )
 
+// MimeTypes stores the MIME content type.
 var MimeTypes = struct {
 	TextPlain   string
 	Tar         string

+ 1 - 1
pkg/ioutils/multireader.go

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

+ 11 - 2
pkg/ioutils/readers.go

@@ -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()

+ 4 - 0
pkg/ioutils/writeflusher.go

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

+ 7 - 1
pkg/ioutils/writers.go

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