setCheckKey is a function to set a check key in the cache of the CheckEngineWithKeys. It takes a permission check request as a key, a permission check response as a value, and returns a boolean value indicating if the operation was successful.
(key *base.PermissionCheckRequest, value *base.PermissionCheckResponse, isRelational bool)
| 140 | // It takes a permission check request as a key, a permission check response as a value, |
| 141 | // and returns a boolean value indicating if the operation was successful. |
| 142 | func (c *CheckEngineWithCache) setCheckKey(key *base.PermissionCheckRequest, value *base.PermissionCheckResponse, isRelational bool) bool { |
| 143 | // If either the key or the value is nil, return false. |
| 144 | if key == nil || value == nil { |
| 145 | return false |
| 146 | } |
| 147 | |
| 148 | // Create a new xxhash object for hashing. |
| 149 | h := xxhash.New() |
| 150 | |
| 151 | // Generate a key string from the permission check request and write it to the hash. |
| 152 | // If there's an error while writing to the hash, return false. |
| 153 | size, err := h.Write([]byte(engines.GenerateKey(key, isRelational))) |
| 154 | if err != nil { |
| 155 | return false |
| 156 | } |
| 157 | |
| 158 | // Compute the hash sum and encode it as a hexadecimal string. |
| 159 | k := hex.EncodeToString(h.Sum(nil)) |
| 160 | |
| 161 | // Set the hashed key and the check result in the cache, using the size of the hashed key as an expiry. |
| 162 | // The Set method should return true if the operation was successful, so return the result. |
| 163 | return c.cache.Set(k, value.GetCan(), int64(size)) |
| 164 | } |
no test coverage detected