mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 00:47:38 -06:00
add functionality to override service in registry
This commit is contained in:
parent
6f9c0241af
commit
d0c00388e6
@ -29,11 +29,42 @@ func Register(descriptor *Descriptor) {
|
||||
}
|
||||
|
||||
func GetServices() []*Descriptor {
|
||||
sort.Slice(services, func(i, j int) bool {
|
||||
return services[i].InitPriority > services[j].InitPriority
|
||||
slice := getServicesWithOverrides()
|
||||
|
||||
sort.Slice(slice, func(i, j int) bool {
|
||||
return slice[i].InitPriority > slice[j].InitPriority
|
||||
})
|
||||
|
||||
return services
|
||||
return slice
|
||||
}
|
||||
|
||||
type OverrideServiceFunc func(descriptor Descriptor) (*Descriptor, bool)
|
||||
|
||||
var overrides []OverrideServiceFunc
|
||||
|
||||
func RegisterOverride(fn OverrideServiceFunc) {
|
||||
overrides = append(overrides, fn)
|
||||
}
|
||||
|
||||
func getServicesWithOverrides() []*Descriptor {
|
||||
slice := []*Descriptor{}
|
||||
for _, s := range services {
|
||||
var descriptor *Descriptor
|
||||
for _, fn := range overrides {
|
||||
if newDescriptor, override := fn(*s); override {
|
||||
descriptor = newDescriptor
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if descriptor != nil {
|
||||
slice = append(slice, descriptor)
|
||||
} else {
|
||||
slice = append(slice, s)
|
||||
}
|
||||
}
|
||||
|
||||
return slice
|
||||
}
|
||||
|
||||
// Service interface is the lowest common shape that services
|
||||
|
Loading…
Reference in New Issue
Block a user