Browse Source

Add md5 func

Volodymyr Tkach 2 years ago
parent
commit
be3feb5d32
1 changed files with 11 additions and 0 deletions
  1. 11 0
      utils/http/helpers/helpers.go

+ 11 - 0
utils/http/helpers/helpers.go

@@ -1,6 +1,8 @@
 package helpers
 
 import (
+	"crypto/md5"
+	"encoding/hex"
 	"encoding/json"
 	"errors"
 	"log"
@@ -24,6 +26,7 @@ import (
 // func HandleTextJavaScript(data string) http.Handler
 // func HandleTextPlain(data string) http.Handler
 // func HandleTextXml(data string) http.Handler
+// func Md5Hash(str []byte) string
 // func MinifyHtmlCode(str string) string
 // func MinifyHtmlJsCode(str string) string
 // func RespondAsBadRequest(w http.ResponseWriter, r *http.Request, err error)
@@ -147,6 +150,14 @@ func HandleTextXml(data string) http.Handler {
 	return HandleFile(data, "text/xml")
 }
 
+func Md5Hash(str []byte) string {
+	h := md5.New()
+	if _, err := h.Write(str); err != nil {
+		return ""
+	}
+	return hex.EncodeToString(h.Sum(nil))
+}
+
 func MinifyHtmlCode(str string) string {
 	str = MinifyHtmlJsCode(str)
 	str = mHtml.ReplaceAllString(str, "><")