admin/sync: Add custom hooks that plugins can register and call

This commit is contained in:
nemunaire 2022-10-31 15:47:20 +01:00
parent d48dd2647c
commit 5d07634d0d

View file

@ -18,6 +18,7 @@ type CheckFileHook func(*fic.EFile, *CheckExceptions) []error
type CheckHintHook func(*fic.EHint, *CheckExceptions) []error
type CheckMDTextHook func(string, *CheckExceptions) []error
type CheckExerciceHook func(*fic.Exercice, *CheckExceptions) []error
type CustomCheckHook func(interface{}, *CheckExceptions) []error
type CheckHooks struct {
flagChoiceHooks []CheckFlagChoiceHook
@ -29,6 +30,7 @@ type CheckHooks struct {
hintHooks []CheckHintHook
mdTextHooks []CheckMDTextHook
exerciceHooks []CheckExerciceHook
customHooks map[string]CustomCheckHook
}
func (h *CheckHooks) RegisterFlagChoiceHook(f CheckFlagChoiceHook) {
@ -67,6 +69,17 @@ func (h *CheckHooks) RegisterExerciceHook(f CheckExerciceHook) {
h.exerciceHooks = append(h.exerciceHooks, f)
}
func (h *CheckHooks) RegisterCustomHook(hookname string, f CustomCheckHook) {
h.customHooks[hookname] = f
}
func (h *CheckHooks) CallCustomHook(hookname string, data interface{}, exceptions *CheckExceptions) []error {
if v, ok := h.customHooks[hookname]; ok {
return v(data, exceptions)
}
return nil
}
func LoadChecksPlugin(fname string) error {
p, err := plugin.Open(fname)
if err != nil {