refactor warning info at api: check regexp

This commit is contained in:
UlricQin 2021-07-16 08:30:48 +08:00
parent 9758e55b72
commit 4e791d50d4
2 changed files with 62 additions and 59 deletions

View File

@ -54,6 +54,9 @@ var (
"Tags filter(Func:%s)'s param invalid": "标签过滤条件(函数:%s)参数不合法(为空或包含空格都不合法)",
"Regexp: %s cannot be compiled": "正则表达式(%s)不合法,无法编译",
"AppendTags(%s) invalid": "附件标签(%s)格式不合法",
"Regexp[%s] matching failed": "正则表达式[%s]匹配失败",
"Regexp[%s] matched, but cannot get substring()": "主正则[%s]匹配成功,但无法匹配到子串",
"TagKey or TagValue contains illegal characters[:,/=\r\n\t]": "标签KEY或者标签值包含非法字符串[:,/=\r\n\t]",
}
langDict = map[string]map[string]string{
"zh": dict,

View File

@ -163,14 +163,14 @@ func regExpCheck(c *gin.Context) {
suc, reRes, isSub := checkRegex(param["re"], param["log"])
if !suc {
ret.Success = false
reRes = genErrMsg("re")
reRes = genErrMsg(param["re"])
ret.Data = append(ret.Data, map[string]string{"re": reRes})
renderData(c, ret, nil)
return
}
if calcMethod == "histogram" && !isSub {
ret.Success = false
reRes = genSubErrMsg("re")
reRes = genSubErrMsg(param["re"])
ret.Data = append(ret.Data, map[string]string{"re": reRes})
renderData(c, ret, nil)
return
@ -193,11 +193,11 @@ func regExpCheck(c *gin.Context) {
if !suc {
// 正则错误
ret.Success = false
tagRes = genErrMsg(tagk)
tagRes = genErrMsg(pat)
} else if !isSub {
// 未匹配出子串
ret.Success = false
tagRes = genSubErrMsg(tagk)
tagRes = genSubErrMsg(pat)
} else if includeIllegalChar(tagRes) || includeIllegalChar(tagk) {
// 保留字报错
ret.Success = false
@ -242,16 +242,16 @@ func includeIllegalChar(s string) bool {
}
// 生成返回错误信息
func genErrMsg(sign string) string {
return _s("regular match failed, please check your configuration:[%s]", sign)
func genErrMsg(pattern string) string {
return _s("Regexp[%s] matching failed", pattern)
}
// 生成子串匹配错误信息
func genSubErrMsg(sign string) string {
return _s("regular match was successful. according to the configuration, it does not get the substring inside(), please check your configuration:[%s]", sign)
func genSubErrMsg(pattern string) string {
return _s("Regexp[%s] matched, but cannot get substring()", pattern)
}
// 生成子串匹配错误信息
func genIllegalCharErrMsg() string {
return _s(`key or value of tag contains illegal characters:[:,/=\r\n\t]`)
return _s(`TagKey or TagValue contains illegal characters[:,/=\r\n\t]`)
}