You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.go 737 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package utils
  2. import (
  3. "encoding/base64"
  4. "fmt"
  5. "strings"
  6. )
  7. func JoinKey(comps ...string) string {
  8. sb := strings.Builder{}
  9. hasTrailingSlash := true
  10. for _, comp := range comps {
  11. if comp == "" {
  12. continue
  13. }
  14. if !hasTrailingSlash {
  15. sb.WriteString("/")
  16. }
  17. sb.WriteString(comp)
  18. hasTrailingSlash = strings.HasSuffix(comp, "/")
  19. }
  20. return sb.String()
  21. }
  22. func BaseKey(key string) string {
  23. return key[strings.LastIndex(key, "/")+1:]
  24. }
  25. func DecodeBase64Hash(hash string) ([]byte, error) {
  26. hashBytes := make([]byte, 32)
  27. n, err := base64.RawStdEncoding.Decode(hashBytes, []byte(hash))
  28. if err != nil {
  29. return nil, err
  30. }
  31. if n != 32 {
  32. return nil, fmt.Errorf("invalid hash length: %d", n)
  33. }
  34. return hashBytes, nil
  35. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。