Initial Commit

This commit is contained in:
Alec Sears
2019-10-15 17:18:42 -05:00
parent e8c5c0c3b9
commit 7c3f26a7f4
8 changed files with 266 additions and 45 deletions

View File

@@ -3,8 +3,10 @@ package main
import (
"crypto/sha1"
"encoding/hex"
"encoding/json"
"time"
"github.com/grafana/grafana_plugin_model/go/datasource"
cache "github.com/patrickmn/go-cache"
)
@@ -30,9 +32,18 @@ func (c *Cache) Get(request string) (interface{}, bool) {
return c.cache.Get(request)
}
// Hash converts the given text string to hash string
func Hash(text string) string {
// HashString converts the given text string to hash string
func HashString(text string) string {
hash := sha1.New()
hash.Write([]byte(text))
return hex.EncodeToString(hash.Sum(nil))
}
// HashDatasourceInfo converts the given datasource info to hash string
func HashDatasourceInfo(dsInfo *datasource.DatasourceInfo) string {
digester := sha1.New()
if err := json.NewEncoder(digester).Encode(dsInfo); err != nil {
panic(err) // This shouldn't be possible but just in case DatasourceInfo changes
}
return hex.EncodeToString(digester.Sum(nil))
}