From 2cbc5adf6d1e0ac22d4f72dabfa48cd593f54c4d Mon Sep 17 00:00:00 2001 From: Tomasen Date: Wed, 9 Dec 2015 14:34:09 +0800 Subject: [PATCH] fix benchmark and cache --- main.go | 9 +++++---- main_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 3f290f7..aaf0d49 100644 --- a/main.go +++ b/main.go @@ -57,21 +57,22 @@ func init() { _BackendAddrCache.Store(make(backendAddrMap)) } -func decryptBackendAddr(line []byte) ([]byte, error) { +func decryptBackendAddr(key []byte) ([]byte, error) { // Try to check cache m1 := _BackendAddrCache.Load().(backendAddrMap) - addr, ok := m1[string(line)] + k1 := string(key) + addr, ok := m1[k1] if ok { return addr, nil } // Try to decrypt it (AES) - addr, err := _Aes256CBC.Decrypt(_SecretPassphase, line) + addr, err := _Aes256CBC.Decrypt(_SecretPassphase, key) if err != nil { return nil, err } - cacheBackendAddr(string(line), addr) + cacheBackendAddr(k1, addr) return addr, nil } diff --git a/main_test.go b/main_test.go index f4c8237..95b8e1d 100644 --- a/main_test.go +++ b/main_test.go @@ -326,7 +326,7 @@ func BenchmarkEncryptText(b *testing.B) { func BenchmarkDecryptText(b *testing.B) { for i := 0; i < b.N; i++ { o := aes256cbc.New() - _, err := o.Decrypt(_secret, _expectAESCiphertext) + _, err := o.DecryptString(_secret, _expectAESCiphertext) if err != nil { panic(err) }