mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Refactor towards template/codegen framework * Add templates for plugin gen * Add Go codegen for plugins; overhaul framework, too * Add new codegen output; assorted framework fixes * Regenerate after merge * Remove accidental commit file, update templates * Export the pfs.Tree loader from plugin types * Print details from cuetsy errors * Generate loaders for all plugins and list in registry * Use pfs_gen.go over lineage_gen.go * Un-un-ignore main file * Introduce simple List static registry for plugins * Last tweaks to codegen * remove unused tvars * Ensure loop-local instances for both vars * Generate pfs parsing in-place in registry * Stop generating pfs_gen.go * Move Tree into pfs, rename subdir * Change package name to match dir * Ignore gocyclo on HTTPServer.getNavTree
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package registry
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/google/wire"
|
|
"github.com/grafana/grafana/pkg/cuectx"
|
|
"github.com/grafana/grafana/pkg/framework/coremodel"
|
|
"github.com/grafana/thema"
|
|
)
|
|
|
|
// CoremodelSet contains all of the wire-style providers related to coremodels.
|
|
var CoremodelSet = wire.NewSet(
|
|
NewBase,
|
|
)
|
|
|
|
// NewBase provides a registry of all coremodels, without any composition of
|
|
// plugin-defined schemas.
|
|
//
|
|
// The returned registry will use the default Grafana thema.Library, defined in
|
|
// pkg/cuectx. If you need control over the thema.Library used by the coremodel
|
|
// lineages, use NewBaseWithLib instead.
|
|
func NewBase() *Base {
|
|
return provideBase(nil)
|
|
}
|
|
|
|
// NewBaseWithLib is the same as NewBase, but allows control over the
|
|
// thema.Library used to initialize the underlying coremodels.
|
|
//
|
|
// Prefer NewBase unless you absolutely need this control.
|
|
func NewBaseWithLib(lib thema.Library) *Base {
|
|
return provideBase(&lib)
|
|
}
|
|
|
|
var (
|
|
baseOnce sync.Once
|
|
defaultBase *Base
|
|
)
|
|
|
|
func provideBase(lib *thema.Library) *Base {
|
|
if lib == nil {
|
|
baseOnce.Do(func() {
|
|
defaultBase = doProvideBase(cuectx.ProvideThemaLibrary())
|
|
})
|
|
return defaultBase
|
|
}
|
|
|
|
return doProvideBase(*lib)
|
|
}
|
|
|
|
// All returns a slice of all registered coremodels.
|
|
//
|
|
// Prefer this method when operating generically across all coremodels.
|
|
//
|
|
// The returned slice is sorted lexicographically by coremodel name. It should
|
|
// not be modified.
|
|
func (b *Base) All() []coremodel.Interface {
|
|
return b.all
|
|
}
|