From 0c2a0e72b3c1b7281e220d6d7e5746d11e078215 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 13 Jun 2023 00:36:54 +0800 Subject: [PATCH] pointers and hashing --- internal/bard/request.go | 4 ++-- internal/bard/utilities.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 internal/bard/utilities.go diff --git a/internal/bard/request.go b/internal/bard/request.go index 7903170..84601f6 100644 --- a/internal/bard/request.go +++ b/internal/bard/request.go @@ -3,7 +3,7 @@ package bard import "time" type BardCache struct { - Bards map[string]Bard + Bards map[string]*Bard } func GarbageCollectCache(cache *BardCache) { @@ -18,7 +18,7 @@ var cache *BardCache func init() { cache = &BardCache{ - Bards: make(map[string]Bard), + Bards: make(map[string]*Bard), } go func() { for { diff --git a/internal/bard/utilities.go b/internal/bard/utilities.go new file mode 100644 index 0000000..669926a --- /dev/null +++ b/internal/bard/utilities.go @@ -0,0 +1,14 @@ +package bard + +import ( + "crypto/md5" + "encoding/hex" +) + +func HashConversation(conversation []string) string { + hash := md5.New() + for _, message := range conversation { + hash.Write([]byte(message)) + } + return hex.EncodeToString(hash.Sum(nil)) +}