package entity import "time" type SMSCode struct { Code string `db:"code"` Mobile string `db:"mobile"` CodeType int `db:"code_type"` IsUsed int `db:"is_used"` CreatedAt string `db:"created_at"` UpdatedAt string `db:"updated_at"` } func (code *SMSCode) IsExpired(period time.Duration) bool { cat, _ := time.Parse("2006-01-02 15:04:05", code.CreatedAt) return cat.Add(period).Format("2006-01-02 15:04:05") < time.Now().Format("2006-01-02 15:04:05") }