mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
8745d7ef1b
* extract kindsys * reinstate kindsys report This may end up living somewhere else (or not! who knows!), but the important part is that I don't get rid of it right now :) I hate the package layout (kindsysreport/codegen) for the main function and will take pretty much any alternative suggestion, but we can change also change it later. Note that the generated report.json is in a different location - anything using this (ops something) needs to be updated. * kindsysreport in codeowners
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package corekind
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/google/wire"
|
|
"github.com/grafana/kindsys"
|
|
"github.com/grafana/thema"
|
|
|
|
"github.com/grafana/grafana/pkg/cuectx"
|
|
)
|
|
|
|
// KindSet contains all of the wire-style providers related to kinds.
|
|
var KindSet = wire.NewSet(
|
|
NewBase,
|
|
)
|
|
|
|
var (
|
|
baseOnce sync.Once
|
|
defaultBase *Base
|
|
)
|
|
|
|
// NewBase provides a registry of all core raw and structured kinds, without any
|
|
// composition of slot kinds.
|
|
//
|
|
// All calling code within grafana/grafana is expected to use Grafana's
|
|
// singleton [thema.Runtime], returned from [cuectx.GrafanaThemaRuntime]. If nil
|
|
// is passed, the singleton will be used.
|
|
func NewBase(rt *thema.Runtime) *Base {
|
|
allrt := cuectx.GrafanaThemaRuntime()
|
|
if rt == nil || rt == allrt {
|
|
baseOnce.Do(func() {
|
|
defaultBase = doNewBase(allrt)
|
|
})
|
|
return defaultBase
|
|
}
|
|
|
|
return doNewBase(rt)
|
|
}
|
|
|
|
// All returns a slice of [kindsys.Core] containing all core Grafana kinds.
|
|
//
|
|
// The returned slice is sorted lexicographically by kind machine name.
|
|
func (b *Base) All() []kindsys.Core {
|
|
ret := make([]kindsys.Core, len(b.all))
|
|
copy(ret, b.all)
|
|
return ret
|
|
}
|