Created
July 23, 2021 03:55
-
-
Save soolaugust/79cf69a3fd142a4de6507ea9cef8a516 to your computer and use it in GitHub Desktop.
get self md5 in Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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