grafana/pkg/coremodel/dashboard/coremodel.go
sam boyer 2a178bd73c
Introduce coremodels framework (extracted from intent-api) (#47653)
* Copy over most of coremodel from intent-api branch

* Fix import paths

* Fix incorrect provider name

* Add root compgen file, fixup componentroot.yaml

* go mod tidy

* Remove compgen for now

* Add dashboard coremodel

* Remove datasource coremodel, for now

* Tweak comments on dashboard struct model

* devenv: add dashboard testing directly

* Fixup dashboard schema for openness, heatmap

* Update Thema to tip

* Fix wire/registry references

* Fix hclog version
2022-04-14 14:54:35 -04:00

41 lines
805 B
Go

package dashboard
import (
"github.com/grafana/thema"
)
// Coremodel contains the foundational schema declaration for dashboards.
type Coremodel struct {
lin thema.Lineage
}
// Lineage returns the canonical dashboard Lineage.
func (c *Coremodel) Lineage() thema.Lineage {
return c.lin
}
func (c *Coremodel) CurrentSchema() thema.Schema {
sch, err := c.lin.Schema(currentVersion)
if err != nil {
// Only reachable if our own schema currentVersion does not exist, which
// can really only happen transitionally during development
panic(err)
}
return sch
}
func (c *Coremodel) GoType() interface{} {
return &model{}
}
func ProvideCoremodel(lib thema.Library) (*Coremodel, error) {
lin, err := Lineage(lib)
if err != nil {
return nil, err
}
return &Coremodel{
lin: lin,
}, nil
}