ExecutableChecksum returns a byte slice containing the SHA256 checksum of the executable. It returns a nil slice if there's an error trying to calculate the checksum.
()
| 93 | // ExecutableChecksum returns a byte slice containing the SHA256 checksum of the executable. |
| 94 | // It returns a nil slice if there's an error trying to calculate the checksum. |
| 95 | func ExecutableChecksum() []byte { |
| 96 | execPath, err := os.Executable() |
| 97 | if err != nil { |
| 98 | return nil |
| 99 | } |
| 100 | execFile, err := os.Open(execPath) |
| 101 | if err != nil { |
| 102 | return nil |
| 103 | } |
| 104 | defer func() { |
| 105 | if err := execFile.Close(); err != nil { |
| 106 | glog.Warningf("error closing file: %v", err) |
| 107 | } |
| 108 | }() |
| 109 | |
| 110 | h := sha256.New() |
| 111 | if _, err := io.Copy(h, execFile); err != nil { |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | return h.Sum(nil) |
| 116 | } |
no test coverage detected