itor/models/card.go

35 lines
550 B
Go
Raw Normal View History

2022-10-09 05:21:00 +00:00
package models
import (
"crypto/md5"
"encoding/hex"
"fmt"
"time"
)
type Card struct {
Id string
Front string
Back string
LastCorrect time.Time
Selected bool
}
func NewCard(front, back string) Card {
id := GetMD5Hash(fmt.Sprintf("%s|%s", front, back))
return Card{Front: front, Back: back, Id: id}
}
func (c Card) FilterValue() string {
return ""
}
func (c Card) ToString() string {
return c.Front
}
func GetMD5Hash(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}