fc5d327494
Error logging and labels were also improved along the way. Signed-off-by: Michael Mayer <michael@liquidbytes.net>
32 lines
567 B
Go
32 lines
567 B
Go
package entity
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
// Keyword for full text search
|
|
type Keyword struct {
|
|
ID uint `gorm:"primary_key"`
|
|
Keyword string `gorm:"type:varchar(64);index;"`
|
|
Skip bool
|
|
}
|
|
|
|
func NewKeyword(keyword string) *Keyword {
|
|
keyword = strings.ToLower(strings.TrimSpace(keyword))
|
|
|
|
result := &Keyword{
|
|
Keyword: keyword,
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func (m *Keyword) FirstOrCreate(db *gorm.DB) *Keyword {
|
|
if err := db.FirstOrCreate(m, "keyword = ?", m.Keyword).Error; err != nil {
|
|
log.Errorf("keyword: %s", err)
|
|
}
|
|
|
|
return m
|
|
}
|