Skip to content

Instantly share code, notes, and snippets.

@soolaugust
Created July 23, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soolaugust/79cf69a3fd142a4de6507ea9cef8a516 to your computer and use it in GitHub Desktop.
Save soolaugust/79cf69a3fd142a4de6507ea9cef8a516 to your computer and use it in GitHub Desktop.
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