gosdk/util/util.go

30 lines
435 B
Go
Raw Normal View History

2024-01-22 22:34:59 +08:00
package util
import (
2024-01-29 22:13:11 +08:00
"crypto/sha256"
"encoding/hex"
2024-01-22 22:34:59 +08:00
"fmt"
"github.com/spf13/cast"
)
func CutTail(str string, length int) string {
if len(str) <= length {
return str
}
return str[0:length]
}
func FloatCut(f float64) float64 {
return cast.ToFloat64(fmt.Sprintf("%.2f", f))
}
2024-01-29 22:13:11 +08:00
func Sha256(s string) string {
hash := sha256.New()
hash.Write([]byte(s))
hashValue := hash.Sum(nil)
return hex.EncodeToString(hashValue)
}