Skip to content

Instantly share code, notes, and snippets.

@soolaugust
Created Jul 23, 2021
Embed
What would you like to do?
get self md5 in Golang
// GetSelfMD5 get md5 of current program
func GetSelfMD5() string {
path, e := exec.LookPath(os.Args[0])
if e != nil {
log.Println(`Self md5sum error: look path fail:`, e)
return ""
}
bs, e := ioutil.ReadFile(path)
if e != nil {
log.Println(`SelfMd5sum error: read file fail:`, e)
return ""
}
sum := md5.Sum(bs)
return hex.EncodeToString(sum[:])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment