-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgotest.go
More file actions
69 lines (61 loc) · 1.19 KB
/
Copy pathgotest.go
File metadata and controls
69 lines (61 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"io/ioutil"
"io"
"crypto/sha1"
"encoding/hex"
"bufio"
"bytes"
"os"
)
type File struct {
Name string
Path string
HashValue string
}
func (file File) Happy() string {
return "Happy"
}
func checkFile(path string, fileName string) (fileTest File) {
fileTest.Name = fileName
fileTest.Path = path
var buffer bytes.Buffer
buffer.WriteString(path)
buffer.WriteString("/")
buffer.WriteString(fileName)
h := sha1.New()
file, err := os.Open(buffer.String())
if err != nil {
}
defer file.Close()
reader := bufio.NewReader(file)
buf := make([]byte, 8096)
for {
n, err := reader.Read(buf)
if err != nil && err != io.EOF {
}
if n == 0 {
break
}
h.Write(buf[:n])
}
fileTest.HashValue = hex.EncodeToString(h.Sum(nil))
fmt.Println(fileTest.HashValue)
fmt.Println(fileTest)
fmt.Println(fileTest.Happy())
return fileTest
}
func main() {
fileList := make([]File,0)
dirList, err := ioutil.ReadDir("./save")
if err != nil {
}
for _, value := range dirList {
if value.IsDir() {
} else {
fileList = append(fileList,checkFile("./save",value.Name()))
}
}
fmt.Println(fileList)
}