func IsDisabled(srv Service) bool {
	canBeDisabled, ok := srv.(CanBeDisabled)
	return ok && canBeDisabled.IsDisabled()
}
IsDisabled returns whether a service is disabled.
package registry
import (
	"context"
	"reflect"
	"sort"
)
type Descriptor struct {
	Name         string
	Instance     Service
	InitPriority Priority
}
var services []*Descriptor
func RegisterServiceWithPriority(instance Service, priority Priority) {
	Register(&Descriptor{
		Name:         reflect.TypeOf(instance).Elem().Name(),
		Instance:     instance,
		InitPriority: priority,
	})
}
func RegisterService(instance Service) {
	Register(&Descriptor{
		Name:         reflect.TypeOf(instance).Elem().Name(),
		Instance:     instance,
		InitPriority: Medium,
	})
}
func Register(descriptor *Descriptor) {
	if descriptor == nil {
		return
	}
	for i, svc := range services {
		if svc.Name == descriptor.Name {
			services[i] = descriptor
			return
		}
	}
	services = append(services, descriptor)
}
func GetService(name string) *Descriptor {
	for _, svc := range services {
		if svc.Name == name {
			return svc
		}
	}
	return nil
}
func GetServices() []*Descriptor {
	slice := getServicesWithOverrides()
	sort.Slice(slice, func(i, j int) bool {
		return slice[i].InitPriority > slice[j].InitPriority
	})
	return slice
}
type OverrideServiceFunc func(descriptor Descriptor) (*Descriptor, bool)
var overrides []OverrideServiceFunc
func RegisterOverride(fn OverrideServiceFunc) {
	overrides = append(overrides, fn)
}
func ClearOverrides() {
	overrides = nil
}
func getServicesWithOverrides() []*Descriptor {
	var 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
}
type Service interface {
	Init() error
}
type CanBeDisabled interface {
	IsDisabled() bool
}
type BackgroundService interface {
	Run(ctx context.Context) error
}