Initial Commit
This commit is contained in:
15
pkg/cache.go
15
pkg/cache.go
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user