push backup
This commit is contained in:
23
pkg/tools/hash/hash.go
Normal file
23
pkg/tools/hash/hash.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func FileMD5(fp string) (string, error) {
|
||||
f, err := os.OpenFile(fp, os.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
hasher := md5.New()
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
sum := hasher.Sum(nil)
|
||||
return hex.EncodeToString(sum), nil
|
||||
}
|
||||
Reference in New Issue
Block a user