Browse Source

golint and go vet

mov
Stephen McQuay 5 years ago
parent
commit
53b1be748a
No known key found for this signature in database GPG Key ID: 1ABF428F71BAFC3D
  1. 9
      arrange.go
  2. 6
      arrange_test.go
  3. 2
      errors.go
  4. 3
      media.go

9
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

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

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

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

Loading…
Cancel
Save