server/libfic/mcq_justification.go
Pierre-Olivier Mercier 01b05aaed0
All checks were successful
continuous-integration/drone/push Build is passing
Implement label only flag
2022-01-21 13:26:52 +01:00

32 lines
737 B
Go

package fic
import (
"errors"
"strconv"
"strings"
)
type FlagMCQLabel struct {
Label string
IdChoice int
}
// IsMCQJustification tells you if this key represent a justification from a MCQ.
func (k FlagKey) IsMCQJustification() bool {
return len(k.Label) > 0 && k.Label[0] == '%'
}
// GetMCQJustification returns the structure corresponding to the given flag.
func (k FlagKey) GetMCQJustification() (fl FlagMCQLabel, err error) {
spl := strings.Split(k.Label, "%")
if len(spl) >= 3 && len(spl[0]) == 0 {
var idChoice int64
idChoice, err = strconv.ParseInt(spl[1], 10, 32)
fl.IdChoice = int(idChoice)
fl.Label = strings.Join(spl[2:], "%")
} else {
err = errors.New("this is not a MCQ justification")
}
return
}