wp-go/helper/strings/strings.go

31 lines
421 B
Go
Raw Normal View History

2023-01-21 11:31:23 +00:00
package strings
2023-01-13 04:31:35 +00:00
import (
"crypto/md5"
"fmt"
"io"
"strings"
)
2023-01-21 11:31:23 +00:00
func Join(s ...string) (str string) {
2023-01-13 04:31:35 +00:00
if len(s) == 1 {
return s[0]
} else if len(s) > 1 {
b := strings.Builder{}
for _, s2 := range s {
b.WriteString(s2)
}
str = b.String()
}
return
}
2023-01-21 11:31:23 +00:00
func Md5(str string) string {
2023-01-13 04:31:35 +00:00
h := md5.New()
_, err := io.WriteString(h, str)
if err != nil {
return ""
}
return fmt.Sprintf("%x", h.Sum(nil))
}