Skip to content

Instantly share code, notes, and snippets.

@stijndehaes
Created April 14, 2022 12:42
Show Gist options
  • Save stijndehaes/6460a3b281f1502cb84a10c8c0e2ae88 to your computer and use it in GitHub Desktop.
Save stijndehaes/6460a3b281f1502cb84a10c8c0e2ae88 to your computer and use it in GitHub Desktop.
Calculate has of object via json
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