admin/sync: Add custom hooks that plugins can register and call
This commit is contained in:
parent
d48dd2647c
commit
5d07634d0d
1 changed files with 13 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ type CheckFileHook func(*fic.EFile, *CheckExceptions) []error
|
||||||
type CheckHintHook func(*fic.EHint, *CheckExceptions) []error
|
type CheckHintHook func(*fic.EHint, *CheckExceptions) []error
|
||||||
type CheckMDTextHook func(string, *CheckExceptions) []error
|
type CheckMDTextHook func(string, *CheckExceptions) []error
|
||||||
type CheckExerciceHook func(*fic.Exercice, *CheckExceptions) []error
|
type CheckExerciceHook func(*fic.Exercice, *CheckExceptions) []error
|
||||||
|
type CustomCheckHook func(interface{}, *CheckExceptions) []error
|
||||||
|
|
||||||
type CheckHooks struct {
|
type CheckHooks struct {
|
||||||
flagChoiceHooks []CheckFlagChoiceHook
|
flagChoiceHooks []CheckFlagChoiceHook
|
||||||
|
|
@ -29,6 +30,7 @@ type CheckHooks struct {
|
||||||
hintHooks []CheckHintHook
|
hintHooks []CheckHintHook
|
||||||
mdTextHooks []CheckMDTextHook
|
mdTextHooks []CheckMDTextHook
|
||||||
exerciceHooks []CheckExerciceHook
|
exerciceHooks []CheckExerciceHook
|
||||||
|
customHooks map[string]CustomCheckHook
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CheckHooks) RegisterFlagChoiceHook(f CheckFlagChoiceHook) {
|
func (h *CheckHooks) RegisterFlagChoiceHook(f CheckFlagChoiceHook) {
|
||||||
|
|
@ -67,6 +69,17 @@ func (h *CheckHooks) RegisterExerciceHook(f CheckExerciceHook) {
|
||||||
h.exerciceHooks = append(h.exerciceHooks, f)
|
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 {
|
func LoadChecksPlugin(fname string) error {
|
||||||
p, err := plugin.Open(fname)
|
p, err := plugin.Open(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Reference in a new issue