diff --git a/http/http_funcs.go b/http/http_funcs.go index 33deb0edc6b77127cdfe0fcfc2f44ae4a194b91e..06b074f2465b34a6865232cc347f09b725057e7b 100644 --- a/http/http_funcs.go +++ b/http/http_funcs.go @@ -1,6 +1,7 @@ package http import ( + "fmt" "net/http" "strconv" "strings" @@ -15,12 +16,20 @@ import ( const defaultLimit = 20 +func _e(format string, a ...interface{}) error { + return fmt.Errorf(_s(format, a...)) +} + +func _s(format string, a ...interface{}) string { + return i18n.Sprintf(format, a...) +} + func dangerous(v interface{}, code ...int) { ierr.Dangerous(v, code...) } func bomb(code int, format string, a ...interface{}) { - ierr.Bomb(code, i18n.Sprintf(format, a...)) + ierr.Bomb(code, _s(format, a...)) } func bind(c *gin.Context, ptr interface{}) { @@ -138,7 +147,7 @@ func renderMessage(c *gin.Context, v interface{}, statusCode ...int) { switch t := v.(type) { case string: - c.JSON(code, gin.H{"err": i18n.Sprintf(t)}) + c.JSON(code, gin.H{"err": _s(t)}) case error: c.JSON(code, gin.H{"err": t.Error()}) } diff --git a/http/router_collect_rule.go b/http/router_collect_rule.go index e3473bf8000f81cab2f5661f675631981e7d9df9..7f0309d713849fd50e28c27d03020339cd0a72f9 100644 --- a/http/router_collect_rule.go +++ b/http/router_collect_rule.go @@ -9,7 +9,6 @@ import ( "github.com/didi/nightingale/v5/cache" "github.com/didi/nightingale/v5/models" - "github.com/didi/nightingale/v5/pkg/i18n" ) type collectRuleForm struct { @@ -244,15 +243,15 @@ func includeIllegalChar(s string) bool { // 生成返回错误信息 func genErrMsg(sign string) string { - return i18n.Sprintf("regular match failed, please check your configuration:[%s]", sign) + return _s("regular match failed, please check your configuration:[%s]", sign) } // 生成子串匹配错误信息 func genSubErrMsg(sign string) string { - return i18n.Sprintf("regular match was successful. according to the configuration, it does not get the substring inside(), please check your configuration:[%s]", sign) + return _s("regular match was successful. according to the configuration, it does not get the substring inside(), please check your configuration:[%s]", sign) } // 生成子串匹配错误信息 func genIllegalCharErrMsg() string { - return i18n.Sprintf(`key or value of tag contains illegal characters:[:,/=\r\n\t]`) + return _s(`key or value of tag contains illegal characters:[:,/=\r\n\t]`) }