Refactor: use InstanceManager for managing ds instances

This commit is contained in:
Alexander Zobnin
2020-08-28 14:40:39 +03:00
parent 2dc514db3a
commit 013fe5c37f
5 changed files with 39 additions and 182 deletions

View File

@@ -3,11 +3,9 @@ package datasource
import (
"crypto/sha1"
"encoding/hex"
"encoding/json"
"time"
"github.com/alexanderzobnin/grafana-zabbix/pkg/cache"
"github.com/grafana/grafana-plugin-sdk-go/backend"
)
// DatasourceCache is a cache for datasource instance.
@@ -40,12 +38,3 @@ func HashString(text string) string {
hash.Write([]byte(text))
return hex.EncodeToString(hash.Sum(nil))
}
// HashDatasourceInfo converts the given datasource info to hash string
func HashDatasourceInfo(dsInfo *backend.DataSourceInstanceSettings) 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))
}