Code cleanup and organization

This commit is contained in:
Jacob Gunther
2023-07-28 15:27:42 -05:00
parent be7a307d19
commit 71ce3ea8b4
3 changed files with 113 additions and 79 deletions

View File

@@ -8,6 +8,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
@@ -136,6 +137,16 @@ func GetInstanceID() (uint16, error) {
return 0, nil
}
// GetCacheKey generates a unique key used for caching status results in Redis.
func GetCacheKey(host string, port uint16, query bool) string {
values := &url.Values{}
values.Set("host", host)
values.Set("port", strconv.FormatUint(uint64(port), 10))
values.Set("query", strconv.FormatBool(query))
return SHA256(values.Encode())
}
// SHA256 returns the result of hashing the input value using SHA256 algorithm.
func SHA256(input string) string {
result := sha1.Sum([]byte(input))