Get gets the hashcode of the executable of this binary
()
| 46 | |
| 47 | // Get gets the hashcode of the executable of this binary |
| 48 | func Get() (string, error) { |
| 49 | var err error |
| 50 | |
| 51 | mx.Lock() |
| 52 | defer mx.Unlock() |
| 53 | |
| 54 | if processBinaryHash != "" { |
| 55 | return processBinaryHash, nil |
| 56 | } |
| 57 | |
| 58 | // Look for the binary of the operator |
| 59 | binaryFileStream, err := Stream() |
| 60 | if err != nil { |
| 61 | return "", err |
| 62 | } |
| 63 | defer func() { |
| 64 | err = binaryFileStream.Close() |
| 65 | }() |
| 66 | |
| 67 | encoder := sha256.New() |
| 68 | _, err = io.Copy(encoder, binaryFileStream) |
| 69 | if err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | |
| 73 | processBinaryHash = fmt.Sprintf("%x", encoder.Sum(nil)) |
| 74 | return processBinaryHash, err |
| 75 | } |
| 76 | |
| 77 | // GetByName gets the hashcode of a binary given its filename |
| 78 | func GetByName(name string) (string, error) { |
no test coverage detected