mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: allow custom mappings with dot (resolve #144)
This commit is contained in:
parent
9fc3c65efe
commit
caf87de887
@ -4,16 +4,10 @@ import (
|
||||
"fmt"
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/mitchellh/hashstructure/v2"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var languageRegex *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
languageRegex = regexp.MustCompile(`^.+\.(.+)$`)
|
||||
}
|
||||
|
||||
type Heartbeat struct {
|
||||
ID uint `gorm:"primary_key" hash:"ignore"`
|
||||
User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" hash:"ignore"`
|
||||
@ -40,15 +34,12 @@ func (h *Heartbeat) Valid() bool {
|
||||
}
|
||||
|
||||
func (h *Heartbeat) Augment(languageMappings map[string]string) {
|
||||
groups := languageRegex.FindAllStringSubmatch(h.Entity, -1)
|
||||
if len(groups) == 0 || len(groups[0]) != 2 {
|
||||
return
|
||||
for ending, value := range languageMappings {
|
||||
if strings.HasSuffix(h.Entity, "."+ending) {
|
||||
h.Language = value
|
||||
return
|
||||
}
|
||||
}
|
||||
ending := groups[0][1]
|
||||
if _, ok := languageMappings[ending]; !ok {
|
||||
return
|
||||
}
|
||||
h.Language, _ = languageMappings[ending]
|
||||
}
|
||||
|
||||
func (h *Heartbeat) GetKey(t uint8) (key string) {
|
||||
|
Loading…
Reference in New Issue
Block a user