Request Hashing
RequestHasher is used to detect if two requests with the same idempotency key have different content. This prevents a classic edge case where a client reuses a key for a completely different operation.
Available Hashers
Section titled “Available Hashers”Body Hasher (Default)
Section titled “Body Hasher (Default)”The simplest approach. It hashes exclusively the request body.
import "github.com/fco-gt/gopotency/hash"
manager, err := idempotency.NewManager(idempotency.Config{ Storage: store, RequestHasher: hash.BodyHasher(),})Full Hasher
Section titled “Full Hasher”A stricter approach that combines the HTTP Method, Path, and Body.
RequestHasher: hash.FullHasher()The data used for the hash follows the pattern: METHOD:PATH:BODY.
Custom Hasher
Section titled “Custom Hasher”You can implement your own hashing logic by fulfilling the RequestHasher interface:
type MyHasher struct{}
func (h *MyHasher) Hash(req *idempotency.Request) (string, error) { // Custom logic: e.g., hash specific headers + body data := fmt.Sprintf("%s:%s", req.Headers["X-Custom-Context"], string(req.Body)) hash := sha256.Sum256([]byte(data)) return hex.EncodeToString(hash[:]), nil}