Created
April 14, 2022 12:42
-
-
Save stijndehaes/6460a3b281f1502cb84a10c8c0e2ae88 to your computer and use it in GitHub Desktop.
Calculate has of object via json
This file contains 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 HashEvent(event interface{}) (string, error) { | |
eventJson, err := json.Marshal(event) | |
if err != nil { | |
return "", err | |
} | |
h := sha256.New() | |
h.Write(eventJson) | |
return fmt.Sprintf("%x", h.Sum(nil)), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment