session.go 488 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "crypto/sha256"
  4. "encoding/json"
  5. "fmt"
  6. )
  7. type Session struct {
  8. Meta
  9. Title string `json:"title"`
  10. Exams map[string]*Exam `json:"exams"`
  11. }
  12. func (s *Session) String() string {
  13. return s.Title
  14. }
  15. func (s *Session) GetHash() string {
  16. return fmt.Sprintf("%x", sha256.Sum256([]byte(s.Title)))
  17. }
  18. func (s *Session) Marshal() ([]byte, error) {
  19. return json.Marshal(s)
  20. }
  21. func (s *Session) Unmarshal(data []byte) error {
  22. return json.Unmarshal(data, s)
  23. }