chore: reorder part two
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package utility
|
||||
|
||||
import (
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
)
|
||||
|
||||
func HashReader(r io.Reader) (string, error) {
|
||||
h := sha512.New()
|
||||
if _, err := io.Copy(h, r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// return the sha checksum in hex
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
// alternatively return in base64
|
||||
//return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package utility
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func RemoveFile(p string) error {
|
||||
err := os.Remove(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseSlogLevel(s string) slog.Level {
|
||||
switch strings.ToLower(s) {
|
||||
case "debug":
|
||||
return slog.LevelDebug
|
||||
case "warn", "warning":
|
||||
return slog.LevelWarn
|
||||
case "error":
|
||||
return slog.LevelError
|
||||
case "info":
|
||||
fallthrough
|
||||
default:
|
||||
return slog.LevelInfo
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user