feat(refacto): move everything in internal package
This allows to install katenary with `go install` and to clean up the project folder.
This commit is contained in:
26
internal/utils/hash.go
Normal file
26
internal/utils/hash.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// HashComposefiles returns a hash of the compose files.
|
||||
func HashComposefiles(files []string) (string, error) {
|
||||
sort.Strings(files) // ensure the order is always the same
|
||||
sha := sha1.New()
|
||||
for _, file := range files {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := io.Copy(sha, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return hex.EncodeToString(sha.Sum(nil)), nil
|
||||
}
|
Reference in New Issue
Block a user