Skip to content

Commit

Permalink
add trim_suffix/prefix functions to match syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Sep 5, 2020
1 parent 40f2994 commit acc2be0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dashboard/src/views/RuleEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ let helpers = {
{text: "Now()", displayText: "Now() time.Time | 当前时间"},
{text: "ParseTime(LAYOUT, VALUE)", displayText: "ParseTime(layout string, value string) time.Time | 时间字符串转时间对象"},
{text: "DailyTimeBetween(START_TIME_STR, END_TIME_STR)", displayText: "DailyTimeBetween(startTime, endTime string) bool | 判断当前时间是否在 startTime 和 endTime 之间(每天),时间格式为 15:04"},
{text: 'SQLFinger(SQL_STR) SQL_STR', displayText: "SQLFinger(sqlStr string) string | 创建 SQL 指纹"}
{text: 'SQLFinger(SQL_STR)', displayText: "SQLFinger(sqlStr string) string | 创建 SQL 指纹"},
{text: 'TrimSuffix(STR, SUFFIX)', displayText: 'TrimSuffix(str, suffix string) string | 去除字符串后缀'},
{text: 'TrimPrefix(STR, PREFIX)', displayText: 'TrimPrefix(str, prefix string) string | 去除字符串前缀'},
],
templates: [
{text: '.Messages MESSAGE_COUNT', displayText: 'Messages(limit int64) []repository.Message | 从分组中获取 MESSAGE_COUNT 个 Message'},
Expand Down
13 changes: 12 additions & 1 deletion internal/matcher/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,15 @@ func (Helpers) ParseTime(layout string, value string) time.Time {
// SQLFinger 将 SQL 转换为其指纹
func (Helpers) SQLFinger(sqlStr string) string {
return parser.Normalize(sqlStr)
}
}

// TrimSuffix 字符串去除后缀
func (Helpers) TrimSuffix(s, suffix string) string {
return strings.TrimSuffix(s, suffix)
}

// TrimPrefix 字符串去除前缀
func (Helpers) TrimPrefix(s, prefix string) string {
return strings.TrimPrefix(s, prefix)
}

0 comments on commit acc2be0

Please sign in to comment.