Browse code

Enable golint part of #14756

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

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2015/08/03 10:45:05
Showing 12 changed files
... ...
@@ -36,10 +36,14 @@ packages=(
36 36
 	graph
37 37
 	image
38 38
 	integration-cli
39
+	pkg/broadcastwriter
39 40
 	pkg/chrootarchive
40 41
 	pkg/directory
41 42
 	pkg/fileutils
43
+	pkg/graphdb
42 44
 	pkg/homedir
45
+	pkg/httputils
46
+	pkg/ioutils
43 47
 	pkg/listenbuffer
44 48
 	pkg/mflag
45 49
 	pkg/mflag/example
... ...
@@ -44,6 +44,7 @@ func (w *BroadcastWriter) Clean() error {
44 44
 	return nil
45 45
 }
46 46
 
47
+// New creates a new BroadcastWriter.
47 48
 func New() *BroadcastWriter {
48 49
 	return &BroadcastWriter{
49 50
 		writers: make(map[io.WriteCloser]struct{}),
... ...
@@ -2,4 +2,6 @@
2 2
 
3 3
 package graphdb
4 4
 
5
-import _ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
5
+import (
6
+	_ "code.google.com/p/gosqlite/sqlite3" // registers sqlite
7
+)
... ...
@@ -2,4 +2,6 @@
2 2
 
3 3
 package graphdb
4 4
 
5
-import _ "github.com/mattn/go-sqlite3" // registers sqlite
5
+import (
6
+	_ "github.com/mattn/go-sqlite3" // registers sqlite
7
+)
... ...
@@ -2,6 +2,7 @@
2 2
 
3 3
 package graphdb
4 4
 
5
+// NewSqliteConn return a new sqlite connection.
5 6
 func NewSqliteConn(root string) (*Database, error) {
6 7
 	panic("Not implemented")
7 8
 }
... ...
@@ -29,28 +29,28 @@ const (
29 29
     `
30 30
 )
31 31
 
32
-// Entity with a unique id
32
+// Entity with a unique id.
33 33
 type Entity struct {
34 34
 	id string
35 35
 }
36 36
 
37
-// An Edge connects two entities together
37
+// An Edge connects two entities together.
38 38
 type Edge struct {
39 39
 	EntityID string
40 40
 	Name     string
41 41
 	ParentID string
42 42
 }
43 43
 
44
-// Entities stores the list of entities
44
+// Entities stores the list of entities.
45 45
 type Entities map[string]*Entity
46 46
 
47
-// Edges stores the relationships between entities
47
+// Edges stores the relationships between entities.
48 48
 type Edges []*Edge
49 49
 
50
-// WalkFunc is a function invoked to process an individual entity
50
+// WalkFunc is a function invoked to process an individual entity.
51 51
 type WalkFunc func(fullPath string, entity *Entity) error
52 52
 
53
-// Database is a graph database for storing entities and their relationships
53
+// Database is a graph database for storing entities and their relationships.
54 54
 type Database struct {
55 55
 	conn *sql.DB
56 56
 	mux  sync.RWMutex
... ...
@@ -80,7 +80,7 @@ func IsNonUniqueNameError(err error) bool {
80 80
 	return false
81 81
 }
82 82
 
83
-// NewDatabase creates a new graph database initialized with a root entity
83
+// NewDatabase creates a new graph database initialized with a root entity.
84 84
 func NewDatabase(conn *sql.DB) (*Database, error) {
85 85
 	if conn == nil {
86 86
 		return nil, fmt.Errorf("Database connection cannot be nil")
... ...
@@ -130,12 +130,12 @@ func NewDatabase(conn *sql.DB) (*Database, error) {
130 130
 	return db, nil
131 131
 }
132 132
 
133
-// Close the underlying connection to the database
133
+// Close the underlying connection to the database.
134 134
 func (db *Database) Close() error {
135 135
 	return db.conn.Close()
136 136
 }
137 137
 
138
-// Set the entity id for a given path
138
+// Set the entity id for a given path.
139 139
 func (db *Database) Set(fullPath, id string) (*Entity, error) {
140 140
 	db.mux.Lock()
141 141
 	defer db.mux.Unlock()
... ...
@@ -171,7 +171,7 @@ func (db *Database) Set(fullPath, id string) (*Entity, error) {
171 171
 	return e, nil
172 172
 }
173 173
 
174
-// Exists returns true if a name already exists in the database
174
+// Exists returns true if a name already exists in the database.
175 175
 func (db *Database) Exists(name string) bool {
176 176
 	db.mux.RLock()
177 177
 	defer db.mux.RUnlock()
... ...
@@ -198,14 +198,14 @@ func (db *Database) setEdge(parentPath, name string, e *Entity, tx *sql.Tx) erro
198 198
 	return nil
199 199
 }
200 200
 
201
-// RootEntity returns the root "/" entity for the database
201
+// RootEntity returns the root "/" entity for the database.
202 202
 func (db *Database) RootEntity() *Entity {
203 203
 	return &Entity{
204 204
 		id: "0",
205 205
 	}
206 206
 }
207 207
 
208
-// Get returns the entity for a given path
208
+// Get returns the entity for a given path.
209 209
 func (db *Database) Get(name string) *Entity {
210 210
 	db.mux.RLock()
211 211
 	defer db.mux.RUnlock()
... ...
@@ -242,8 +242,8 @@ func (db *Database) get(name string) (*Entity, error) {
242 242
 
243 243
 }
244 244
 
245
-// List all entities by from the name
246
-// The key will be the full path of the entity
245
+// List all entities by from the name.
246
+// The key will be the full path of the entity.
247 247
 func (db *Database) List(name string, depth int) Entities {
248 248
 	db.mux.RLock()
249 249
 	defer db.mux.RUnlock()
... ...
@@ -282,7 +282,7 @@ func (db *Database) Walk(name string, walkFunc WalkFunc, depth int) error {
282 282
 	return nil
283 283
 }
284 284
 
285
-// Children returns the children of the specified entity
285
+// Children returns the children of the specified entity.
286 286
 func (db *Database) Children(name string, depth int) ([]WalkMeta, error) {
287 287
 	db.mux.RLock()
288 288
 	defer db.mux.RUnlock()
... ...
@@ -295,7 +295,7 @@ func (db *Database) Children(name string, depth int) ([]WalkMeta, error) {
295 295
 	return db.children(e, name, depth, nil)
296 296
 }
297 297
 
298
-// Parents returns the parents of a specified entity
298
+// Parents returns the parents of a specified entity.
299 299
 func (db *Database) Parents(name string) ([]string, error) {
300 300
 	db.mux.RLock()
301 301
 	defer db.mux.RUnlock()
... ...
@@ -307,7 +307,7 @@ func (db *Database) Parents(name string) ([]string, error) {
307 307
 	return db.parents(e)
308 308
 }
309 309
 
310
-// Refs returns the refrence count for a specified id
310
+// Refs returns the refrence count for a specified id.
311 311
 func (db *Database) Refs(id string) int {
312 312
 	db.mux.RLock()
313 313
 	defer db.mux.RUnlock()
... ...
@@ -319,7 +319,7 @@ func (db *Database) Refs(id string) int {
319 319
 	return count
320 320
 }
321 321
 
322
-// RefPaths returns all the id's path references
322
+// RefPaths returns all the id's path references.
323 323
 func (db *Database) RefPaths(id string) Edges {
324 324
 	db.mux.RLock()
325 325
 	defer db.mux.RUnlock()
... ...
@@ -347,7 +347,7 @@ func (db *Database) RefPaths(id string) Edges {
347 347
 	return refs
348 348
 }
349 349
 
350
-// Delete the reference to an entity at a given path
350
+// Delete the reference to an entity at a given path.
351 351
 func (db *Database) Delete(name string) error {
352 352
 	db.mux.Lock()
353 353
 	defer db.mux.Unlock()
... ...
@@ -446,6 +446,7 @@ func (db *Database) Rename(currentName, newName string) error {
446 446
 	return nil
447 447
 }
448 448
 
449
+// WalkMeta stores the walk metadata.
449 450
 type WalkMeta struct {
450 451
 	Parent   *Entity
451 452
 	Entity   *Entity
... ...
@@ -522,7 +523,7 @@ func (db *Database) parents(e *Entity) (parents []string, err error) {
522 522
 	return parents, nil
523 523
 }
524 524
 
525
-// Return the entity based on the parent path and name
525
+// Return the entity based on the parent path and name.
526 526
 func (db *Database) child(parent *Entity, name string) *Entity {
527 527
 	var id string
528 528
 	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 {
531 531
 	return &Entity{id}
532 532
 }
533 533
 
534
-// ID returns the id used to reference this entity
534
+// ID returns the id used to reference this entity.
535 535
 func (e *Entity) ID() string {
536 536
 	return e.id
537 537
 }
538 538
 
539
-// Paths returns the paths sorted by depth
539
+// Paths returns the paths sorted by depth.
540 540
 func (e Entities) Paths() []string {
541 541
 	out := make([]string, len(e))
542 542
 	var i int
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/pkg/jsonmessage"
11 11
 )
12 12
 
13
-// Download requests a given URL and returns an io.Reader
13
+// Download requests a given URL and returns an io.Reader.
14 14
 func Download(url string) (resp *http.Response, err error) {
15 15
 	if resp, err = http.Get(url); err != nil {
16 16
 		return nil, err
... ...
@@ -21,7 +21,7 @@ func Download(url string) (resp *http.Response, err error) {
21 21
 	return resp, nil
22 22
 }
23 23
 
24
-// NewHTTPRequestError returns a JSON response error
24
+// NewHTTPRequestError returns a JSON response error.
25 25
 func NewHTTPRequestError(msg string, res *http.Response) error {
26 26
 	return &jsonmessage.JSONError{
27 27
 		Message: msg,
... ...
@@ -29,14 +29,15 @@ func NewHTTPRequestError(msg string, res *http.Response) error {
29 29
 	}
30 30
 }
31 31
 
32
+// ServerHeader contains the server information.
32 33
 type ServerHeader struct {
33 34
 	App string // docker
34 35
 	Ver string // 1.8.0-dev
35 36
 	OS  string // windows or linux
36 37
 }
37 38
 
38
-// parseServerHeader extracts pieces from am HTTP server header
39
-// which is in the format "docker/version (os)" eg docker/1.8.0-dev (windows)
39
+// ParseServerHeader extracts pieces from an HTTP server header
40
+// which is in the format "docker/version (os)" eg docker/1.8.0-dev (windows).
40 41
 func ParseServerHeader(hdr string) (*ServerHeader, error) {
41 42
 	re := regexp.MustCompile(`.*\((.+)\).*$`)
42 43
 	r := &ServerHeader{}
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"net/http"
6 6
 )
7 7
 
8
+// MimeTypes stores the MIME content type.
8 9
 var MimeTypes = struct {
9 10
 	TextPlain   string
10 11
 	Tar         string
... ...
@@ -53,7 +53,7 @@ func (r *multiReadSeeker) Seek(offset int64, whence int) (int64, error) {
53 53
 			}
54 54
 
55 55
 			if rdrOffset == s && i != len(r.readers)-1 {
56
-				idx += 1
56
+				idx++
57 57
 				rdrOffset = 0
58 58
 			}
59 59
 			r.pos = &pos{idx, rdrOffset}
... ...
@@ -23,6 +23,7 @@ func (r *readCloserWrapper) Close() error {
23 23
 	return r.closer()
24 24
 }
25 25
 
26
+// NewReadCloserWrapper returns a new io.ReadCloser.
26 27
 func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser {
27 28
 	return &readCloserWrapper{
28 29
 		Reader: r,
... ...
@@ -43,6 +44,7 @@ func (r *readerErrWrapper) Read(p []byte) (int, error) {
43 43
 	return n, err
44 44
 }
45 45
 
46
+// NewReaderErrWrapper returns a new io.Reader.
46 47
 func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader {
47 48
 	return &readerErrWrapper{
48 49
 		reader: r,
... ...
@@ -68,7 +70,8 @@ type bufReader struct {
68 68
 	maxReadDataReset     int64
69 69
 }
70 70
 
71
-func NewBufReader(r io.Reader) *bufReader {
71
+// NewBufReader returns a new bufReader.
72
+func NewBufReader(r io.Reader) io.ReadCloser {
72 73
 	timeout := rand.New(rndSrc).Intn(120) + 180
73 74
 
74 75
 	reader := &bufReader{
... ...
@@ -86,7 +89,8 @@ func NewBufReader(r io.Reader) *bufReader {
86 86
 	return reader
87 87
 }
88 88
 
89
-func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer *bytes.Buffer) *bufReader {
89
+// NewBufReaderWithDrainbufAndBuffer returns a BufReader with drainBuffer and buffer.
90
+func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer *bytes.Buffer) io.ReadCloser {
90 91
 	reader := &bufReader{
91 92
 		buf:      buffer,
92 93
 		drainBuf: drainBuffer,
... ...
@@ -210,6 +214,7 @@ func (r *bufReader) Read(p []byte) (n int, err error) {
210 210
 	}
211 211
 }
212 212
 
213
+// Close closes the bufReader
213 214
 func (r *bufReader) Close() error {
214 215
 	closer, ok := r.reader.(io.ReadCloser)
215 216
 	if !ok {
... ...
@@ -218,6 +223,7 @@ func (r *bufReader) Close() error {
218 218
 	return closer.Close()
219 219
 }
220 220
 
221
+// HashData returns the sha256 sum of src.
221 222
 func HashData(src io.Reader) (string, error) {
222 223
 	h := sha256.New()
223 224
 	if _, err := io.Copy(h, src); err != nil {
... ...
@@ -226,6 +232,8 @@ func HashData(src io.Reader) (string, error) {
226 226
 	return "sha256:" + hex.EncodeToString(h.Sum(nil)), nil
227 227
 }
228 228
 
229
+// OnEOFReader wraps a io.ReadCloser and a function
230
+// the fuction will run at the end of file or close the file.
229 231
 type OnEOFReader struct {
230 232
 	Rc io.ReadCloser
231 233
 	Fn func()
... ...
@@ -239,6 +247,7 @@ func (r *OnEOFReader) Read(p []byte) (n int, err error) {
239 239
 	return
240 240
 }
241 241
 
242
+// Close closes the file and run the function.
242 243
 func (r *OnEOFReader) Close() error {
243 244
 	err := r.Rc.Close()
244 245
 	r.runFunc()
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"sync"
7 7
 )
8 8
 
9
+// WriteFlusher wraps the Write and Flush operation.
9 10
 type WriteFlusher struct {
10 11
 	sync.Mutex
11 12
 	w       io.Writer
... ...
@@ -30,12 +31,15 @@ func (wf *WriteFlusher) Flush() {
30 30
 	wf.flusher.Flush()
31 31
 }
32 32
 
33
+// Flushed returns the state of flushed.
34
+// If it's flushed, return true, or else it return false.
33 35
 func (wf *WriteFlusher) Flushed() bool {
34 36
 	wf.Lock()
35 37
 	defer wf.Unlock()
36 38
 	return wf.flushed
37 39
 }
38 40
 
41
+// NewWriteFlusher returns a new WriteFlusher.
39 42
 func NewWriteFlusher(w io.Writer) *WriteFlusher {
40 43
 	var flusher http.Flusher
41 44
 	if f, ok := w.(http.Flusher); ok {
... ...
@@ -2,6 +2,7 @@ package ioutils
2 2
 
3 3
 import "io"
4 4
 
5
+// NopWriter represents a type which write operation is nop.
5 6
 type NopWriter struct{}
6 7
 
7 8
 func (*NopWriter) Write(buf []byte) (int, error) {
... ...
@@ -14,12 +15,15 @@ type nopWriteCloser struct {
14 14
 
15 15
 func (w *nopWriteCloser) Close() error { return nil }
16 16
 
17
+// NopWriteCloser returns a nopWriteCloser.
17 18
 func NopWriteCloser(w io.Writer) io.WriteCloser {
18 19
 	return &nopWriteCloser{w}
19 20
 }
20 21
 
22
+// NopFlusher represents a type which flush opetatin is nop.
21 23
 type NopFlusher struct{}
22 24
 
25
+// Flush is a nop operation.
23 26
 func (f *NopFlusher) Flush() {}
24 27
 
25 28
 type writeCloserWrapper struct {
... ...
@@ -31,6 +35,7 @@ func (r *writeCloserWrapper) Close() error {
31 31
 	return r.closer()
32 32
 }
33 33
 
34
+// NewWriteCloserWrapper returns a new io.WriteCloser.
34 35
 func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
35 36
 	return &writeCloserWrapper{
36 37
 		Writer: r,
... ...
@@ -38,7 +43,7 @@ func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
38 38
 	}
39 39
 }
40 40
 
41
-// Wrap a concrete io.Writer and hold a count of the number
41
+// WriteCounter wraps a concrete io.Writer and hold a count of the number
42 42
 // of bytes written to the writer during a "session".
43 43
 // This can be convenient when write return is masked
44 44
 // (e.g., json.Encoder.Encode())
... ...
@@ -47,6 +52,7 @@ type WriteCounter struct {
47 47
 	Writer io.Writer
48 48
 }
49 49
 
50
+// NewWriteCounter returns a new WriteCounter.
50 51
 func NewWriteCounter(w io.Writer) *WriteCounter {
51 52
 	return &WriteCounter{
52 53
 		Writer: w,