golint and go vet
This commit is contained in:
parent
284a478a2f
commit
53b1be748a
@ -42,6 +42,7 @@ func mtime(path string) (time.Time, error) {
|
|||||||
return s.ModTime(), nil
|
return s.ModTime(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrepOutput creates all possible content-address prefix directories.
|
||||||
func PrepOutput(root string) error {
|
func PrepOutput(root string) error {
|
||||||
for i := 0; i <= 0xff; i++ {
|
for i := 0; i <= 0xff; i++ {
|
||||||
dirname := filepath.Join(root, "content", fmt.Sprintf("%02x", i))
|
dirname := filepath.Join(root, "content", fmt.Sprintf("%02x", i))
|
||||||
@ -55,6 +56,7 @@ func PrepOutput(root string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Source returns sends all files that match known extensions.
|
||||||
func Source(root string) <-chan string {
|
func Source(root string) <-chan string {
|
||||||
out := make(chan string)
|
out := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
@ -82,6 +84,10 @@ func Source(root string) <-chan string {
|
|||||||
return out
|
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 {
|
func Parse(in <-chan string) <-chan Media {
|
||||||
out := make(chan Media)
|
out := make(chan Media)
|
||||||
go func() {
|
go func() {
|
||||||
@ -105,6 +111,8 @@ func Parse(in <-chan string) <-chan Media {
|
|||||||
return out
|
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 {
|
func Move(in <-chan Media, root string) <-chan error {
|
||||||
out := make(chan error)
|
out := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
@ -198,6 +206,7 @@ func _parse(path string) (Media, error) {
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge implements fan-in.
|
||||||
func Merge(cs []<-chan Media) <-chan Media {
|
func Merge(cs []<-chan Media) <-chan Media {
|
||||||
out := make(chan Media)
|
out := make(chan Media)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@ -194,8 +194,8 @@ func TestMoveCollision(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSundry(t *testing.T) {
|
func TestSundry(t *testing.T) {
|
||||||
fmt.Sprintf("%v", NotMedia{"hi"})
|
_ = fmt.Sprintf("%v", NotMedia{"hi"})
|
||||||
fmt.Sprintf("%v", Dup{"hi"})
|
_ = fmt.Sprintf("%v", Dup{"hi"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFlow(t *testing.T) {
|
func TestFlow(t *testing.T) {
|
||||||
@ -272,7 +272,7 @@ func TestFlow(t *testing.T) {
|
|||||||
|
|
||||||
for err := range Move(Merge(streams), tmp) {
|
for err := range Move(Merge(streams), tmp) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v")
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package arrange
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
// NotMedia is for unkown filetypes.
|
||||||
type NotMedia struct {
|
type NotMedia struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
@ -10,6 +11,7 @@ func (nm NotMedia) Error() string {
|
|||||||
return fmt.Sprintf("not media: %q", nm.Path)
|
return fmt.Sprintf("not media: %q", nm.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dup indicates a file with duplicate content.
|
||||||
type Dup struct {
|
type Dup struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
3
media.go
3
media.go
@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Media is the high-level filetype that can be arranged.
|
||||||
type Media struct {
|
type Media struct {
|
||||||
Path string
|
Path string
|
||||||
Hash string
|
Hash string
|
||||||
@ -15,6 +16,8 @@ type Media struct {
|
|||||||
Time time.Time
|
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 {
|
func (m Media) Move(root string) error {
|
||||||
f, err := os.Open(m.Path)
|
f, err := os.Open(m.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user