-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.go
39 lines (36 loc) · 1.09 KB
/
rules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"errors"
"regexp"
)
type CompiledRule struct {
TitlePattern regexp.Regexp
ItemPattern regexp.Regexp
LinkPattern regexp.Regexp
DescriptionPattern regexp.Regexp
}
func CompileRule(rule *Rule) (*CompiledRule, error) {
compiledItemPattern, err := regexp.Compile(rule.ItemPattern)
if err != nil {
return nil, errors.New("compilation rule error: " + err.Error())
}
compiledTitlePattern, err := regexp.Compile(rule.TitlePattern)
if err != nil {
return nil, errors.New("compilation rule error: " + err.Error())
}
compiledLinkPattern, err := regexp.Compile(rule.LinkPattern)
if err != nil {
return nil, errors.New("compilation rule error: " + err.Error())
}
compiledDescriptionPattern, err := regexp.Compile(rule.DescriptionPattern)
if err != nil {
return nil, errors.New("compilation rule error: " + err.Error())
}
result := CompiledRule{
TitlePattern: *compiledTitlePattern,
DescriptionPattern: *compiledDescriptionPattern,
ItemPattern: *compiledItemPattern,
LinkPattern: *compiledLinkPattern,
}
return &result, nil
}