mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
27 lines
410 B
Go
27 lines
410 B
Go
package sha256sum
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// For calculates the SHA256 sum for the given file
|
|
func For(path string) (result string, err error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer func() { _ = file.Close() }()
|
|
|
|
hash := sha256.New()
|
|
_, err = io.Copy(hash, file)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
result = hex.EncodeToString(hash.Sum(nil))
|
|
return
|
|
}
|