How to get a MD5 hash from a string in Golang?

This is how I started to get a md5 hash from a string:

import "crypto/md5"

var original = "my string comes here"
var hash = md5.New(original)

But obviously this is not how it works. Can someone provide me a working sample for this?


Solution 1:

Reference Sum,For me,following work well:

package main

import (
    "crypto/md5"
    "fmt"
)

func main() {
    data := []byte("hello")
    fmt.Printf("%x", md5.Sum(data))
}

Solution 2:

import (
    "crypto/md5"
    "encoding/hex"
)

func GetMD5Hash(text string) string {
   hash := md5.Sum([]byte(text))
   return hex.EncodeToString(hash[:])
}