package main import ( "fmt" "os" "path/filepath" "porg/fileop" "porg/pipe" ) type SHAInfo struct { path string sha256 string } type MoveCommand struct { src string dest string } func Calculate(file string) *SHAInfo { sha, err := fileop.CalculateSHA256(file) if err != nil { fmt.Println(err) return nil } else { return &SHAInfo{path: file, sha256: sha} } } func Move(info *SHAInfo) *MoveCommand { base := filepath.Dir(info.path) ext := filepath.Ext(info.path) head := info.sha256[0:2] tail := info.sha256[2:] newPath := fmt.Sprintf("%s/%s/%s%s", base, head, tail, ext) return &MoveCommand{src: info.path, dest: newPath} } func Apply(move *MoveCommand) { dir := filepath.Dir(move.dest) os.Mkdir(dir, 0755) if err := os.Rename(move.src, move.dest); err != nil { fmt.Println(err) } } func main() { files := fileop.WalkFolder("") shas := pipe.Proc(files, 8, Calculate) cmds := pipe.Proc(shas, 1, Move) pipe.TailProc(cmds, 4, Apply) }