package models import ( "crypto/sha256" "encoding/json" "fmt" "strings" ) type Exam struct { Meta Name string Participant *Participant Quizzes []*Quiz } func (e *Exam) String() string { return fmt.Sprintf("Exam ID %v with %v quizzes.", e.ID, len(e.Quizzes)) } func (e *Exam) GetHash() string { return fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{e.Name, e.Participant.GetHash()}, "")))) } func (e *Exam) Marshal() ([]byte, error) { return json.Marshal(e) } func (e *Exam) Unmarshal(data []byte) error { return json.Unmarshal(data, e) }