sync: Report custom errors
This commit is contained in:
parent
08ea1bac0d
commit
c78545c18b
17 changed files with 510 additions and 137 deletions
83
admin/sync/hooks.go
Normal file
83
admin/sync/hooks.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"plugin"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
var hooks = &CheckHooks{}
|
||||
|
||||
type CheckFlagChoiceHook func(*fic.FlagChoice) []error
|
||||
type CheckFlagKeyHook func(*fic.FlagKey, string) []error
|
||||
type CheckFlagKeyWithChoicesHook func(*fic.FlagKey, string, []*fic.FlagChoice) []error
|
||||
type CheckFlagLabelHook func(*fic.FlagLabel) []error
|
||||
type CheckFlagMCQHook func(*fic.MCQ, []*fic.MCQ_entry) []error
|
||||
type CheckFileHook func(*fic.EFile) []error
|
||||
type CheckHintHook func(*fic.EHint) []error
|
||||
|
||||
type CheckHooks struct {
|
||||
flagChoiceHooks []CheckFlagChoiceHook
|
||||
flagKeyHooks []CheckFlagKeyHook
|
||||
flagKeyWithChoicesHooks []CheckFlagKeyWithChoicesHook
|
||||
flagLabelHooks []CheckFlagLabelHook
|
||||
flagMCQHooks []CheckFlagMCQHook
|
||||
fileHooks []CheckFileHook
|
||||
hintHooks []CheckHintHook
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFlagChoiceHook(f CheckFlagChoiceHook) {
|
||||
h.flagChoiceHooks = append(h.flagChoiceHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFlagKeyHook(f CheckFlagKeyHook) {
|
||||
h.flagKeyHooks = append(h.flagKeyHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFlagKeyWithChoicesHook(f CheckFlagKeyWithChoicesHook) {
|
||||
h.flagKeyWithChoicesHooks = append(h.flagKeyWithChoicesHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFlagLabelHook(f CheckFlagLabelHook) {
|
||||
h.flagLabelHooks = append(h.flagLabelHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFlagMCQHook(f CheckFlagMCQHook) {
|
||||
h.flagMCQHooks = append(h.flagMCQHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterFileHook(f CheckFileHook) {
|
||||
h.fileHooks = append(h.fileHooks, f)
|
||||
}
|
||||
|
||||
func (h *CheckHooks) RegisterHintHook(f CheckHintHook) {
|
||||
h.hintHooks = append(h.hintHooks, f)
|
||||
}
|
||||
|
||||
func LoadChecksPlugin(fname string) error {
|
||||
p, err := plugin.Open(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
register, err := p.Lookup("RegisterChecksHooks")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
register.(func(*CheckHooks))(hooks)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type CheckPluginList []string
|
||||
|
||||
func (l *CheckPluginList) String() string {
|
||||
return fmt.Sprintf("%v", *l)
|
||||
}
|
||||
|
||||
func (l *CheckPluginList) Set(value string) error {
|
||||
*l = append(*l, value)
|
||||
return nil
|
||||
}
|
Reference in a new issue