Created
April 10, 2025 05:12
-
-
Save haileyok/b56b88803e3044c84c3c99a60270fdd9 to your computer and use it in GitHub Desktop.
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
func (f *F) GetImageHash(filepath string) (string, error) { | |
start := time.Now() | |
cmd := exec.Command(f.pdqPath, filepath) | |
out, err := cmd.StdoutPipe() | |
if err != nil { | |
return "", err | |
} | |
if err := cmd.Start(); err != nil { | |
return "", err | |
} | |
b, err := io.ReadAll(out) | |
if err != nil { | |
return "", err | |
} | |
if err := cmd.Wait(); err != nil { | |
return "", err | |
} | |
respParts := strings.Split(string(b), ",") | |
if len(respParts) != 3 { | |
return "", fmt.Errorf("invalid response from pdq") | |
} | |
f.hashHist.WithLabelValues("hash").Observe(time.Since(start).Seconds()) | |
return respParts[0], nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment