From 53b1be748a6ff3f79db2f5a824624be3f54fc3a3 Mon Sep 17 00:00:00 2001 From: "Stephen McQuay (smcquay)" Date: Thu, 19 May 2016 21:29:17 -0700 Subject: [PATCH] golint and go vet --- arrange.go | 9 +++++++++ arrange_test.go | 6 +++--- errors.go | 2 ++ media.go | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arrange.go b/arrange.go index 3a43057..edfdc17 100644 --- a/arrange.go +++ b/arrange.go @@ -42,6 +42,7 @@ func mtime(path string) (time.Time, error) { return s.ModTime(), nil } +// PrepOutput creates all possible content-address prefix directories. func PrepOutput(root string) error { for i := 0; i <= 0xff; i++ { dirname := filepath.Join(root, "content", fmt.Sprintf("%02x", i)) @@ -55,6 +56,7 @@ func PrepOutput(root string) error { return nil } +// Source returns sends all files that match known extensions. func Source(root string) <-chan string { out := make(chan string) go func() { @@ -82,6 +84,10 @@ func Source(root string) <-chan string { return out } +// Parse runs the file parser for each file on input chan, and sends results +// down output chan. +// +// Exists so that it can be called many times concurrently. func Parse(in <-chan string) <-chan Media { out := make(chan Media) go func() { @@ -105,6 +111,8 @@ func Parse(in <-chan string) <-chan Media { return out } +// Move calls Move on each Media on input chan. It is the first step in the +// pipeline after fan-in. func Move(in <-chan Media, root string) <-chan error { out := make(chan error) go func() { @@ -198,6 +206,7 @@ func _parse(path string) (Media, error) { return r, nil } +// Merge implements fan-in. func Merge(cs []<-chan Media) <-chan Media { out := make(chan Media) var wg sync.WaitGroup diff --git a/arrange_test.go b/arrange_test.go index a24ddda..03fa1d3 100644 --- a/arrange_test.go +++ b/arrange_test.go @@ -194,8 +194,8 @@ func TestMoveCollision(t *testing.T) { } func TestSundry(t *testing.T) { - fmt.Sprintf("%v", NotMedia{"hi"}) - fmt.Sprintf("%v", Dup{"hi"}) + _ = fmt.Sprintf("%v", NotMedia{"hi"}) + _ = fmt.Sprintf("%v", Dup{"hi"}) } func TestFlow(t *testing.T) { @@ -272,7 +272,7 @@ func TestFlow(t *testing.T) { for err := range Move(Merge(streams), tmp) { if err != nil { - t.Errorf("unexpected error: %v") + t.Errorf("unexpected error: %v", err) } } diff --git a/errors.go b/errors.go index 3465d2c..8d5996d 100644 --- a/errors.go +++ b/errors.go @@ -2,6 +2,7 @@ package arrange import "fmt" +// NotMedia is for unkown filetypes. type NotMedia struct { Path string } @@ -10,6 +11,7 @@ func (nm NotMedia) Error() string { return fmt.Sprintf("not media: %q", nm.Path) } +// Dup indicates a file with duplicate content. type Dup struct { Path string } diff --git a/media.go b/media.go index 25f0fbe..6a5743b 100644 --- a/media.go +++ b/media.go @@ -8,6 +8,7 @@ import ( "time" ) +// Media is the high-level filetype that can be arranged. type Media struct { Path string Hash string @@ -15,6 +16,8 @@ type Media struct { Time time.Time } +// Move is called to push Media into its final destination, by content address +// and by date. func (m Media) Move(root string) error { f, err := os.Open(m.Path) if err != nil {