commit b1781b9cfa027769a9f8ae49b04520d7811e4fbe
parent 6f2c821548283df50eeea7f59d8c9fb0aec1fa49
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 23 Jul 2024 08:47:37 +0900
add qid() to Ans interface
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/main.go b/main.go
@@ -99,7 +99,7 @@ func (q *Question) makeAns(ans map[string][]string) ([]Ans, error) {
}
switch q.T {
case "check":
- var l []string
+ l := make([]string, 0)
for _, i := range a {
if i == "" { // empty answer for "その他"
continue
@@ -128,6 +128,9 @@ func (q *Question) makeAns(ans map[string][]string) ([]Ans, error) {
if len(a) != 1 {
return nil, fmt.Errorf("invalid length %d for %s.\n", len(a), q.Qid)
}
+ if a[0] == "" { // empty answer
+ return []Ans{RadioAns{Qid: q.Qid, Type: q.T, Ans: ""}}, nil
+ }
i, err := strconv.Atoi(a[0])
if err != nil {
return nil, fmt.Errorf("invalid answer %s for %s.", a[0], q.Qid)
@@ -156,6 +159,7 @@ func (q *Question) makeAns(ans map[string][]string) ([]Ans, error) {
}
type Ans interface {
+ qid() string
}
type TextAns struct {
@@ -163,18 +167,21 @@ type TextAns struct {
Type string
Ans string
}
+func (a TextAns) qid() string { return a.Qid }
type RadioAns struct {
Qid string
Type string
Ans string
}
+func (a RadioAns) qid() string { return a.Qid }
type CheckAns struct {
Qid string
Type string
Ans []string
}
+func (a CheckAns) qid() string { return a.Qid }
func formatAns(q Part, ans map[string][]string) ([]byte, error) {
return nil, nil