golint and go vet

This commit is contained in:
Stephen McQuay 2016-05-19 21:29:17 -07:00
parent 284a478a2f
commit 53b1be748a
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D
4 changed files with 17 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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