We sprinkle a bit of generic magic to refactor a lot of duplicate code. To avoid exposing unnecessary code, I duplicated the function twice. But let me know if you have strong opinions about this. https://mattermost.atlassian.net/browse/MM-60171 ```release-note NONE ``` --------- Co-authored-by: Mattermost Build <build@mattermost.com>
33 строки
639 B
Go
33 строки
639 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package platform
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/base64"
|
|
)
|
|
|
|
func getKeyHash(key string) string {
|
|
hash := sha256.New()
|
|
hash.Write([]byte(key))
|
|
return base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
|
}
|
|
|
|
func maxInt(a, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
// allocateCacheTargets is used to fill target value types
|
|
// for getting items from cache.
|
|
func allocateCacheTargets[T any](l int) []any {
|
|
toPass := make([]any, 0, l)
|
|
for i := 0; i < l; i++ {
|
|
toPass = append(toPass, new(T))
|
|
}
|
|
return toPass
|
|
}
|