提交 9758e55b 编写于 作者: U UlricQin

code refactor: extract _s and _e func

上级 473239cc
package http package http
import ( import (
"fmt"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
...@@ -15,12 +16,20 @@ import ( ...@@ -15,12 +16,20 @@ import (
const defaultLimit = 20 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) { func dangerous(v interface{}, code ...int) {
ierr.Dangerous(v, code...) ierr.Dangerous(v, code...)
} }
func bomb(code int, format string, a ...interface{}) { 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{}) { func bind(c *gin.Context, ptr interface{}) {
...@@ -138,7 +147,7 @@ func renderMessage(c *gin.Context, v interface{}, statusCode ...int) { ...@@ -138,7 +147,7 @@ func renderMessage(c *gin.Context, v interface{}, statusCode ...int) {
switch t := v.(type) { switch t := v.(type) {
case string: case string:
c.JSON(code, gin.H{"err": i18n.Sprintf(t)}) c.JSON(code, gin.H{"err": _s(t)})
case error: case error:
c.JSON(code, gin.H{"err": t.Error()}) c.JSON(code, gin.H{"err": t.Error()})
} }
......
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"github.com/didi/nightingale/v5/cache" "github.com/didi/nightingale/v5/cache"
"github.com/didi/nightingale/v5/models" "github.com/didi/nightingale/v5/models"
"github.com/didi/nightingale/v5/pkg/i18n"
) )
type collectRuleForm struct { type collectRuleForm struct {
...@@ -244,15 +243,15 @@ func includeIllegalChar(s string) bool { ...@@ -244,15 +243,15 @@ func includeIllegalChar(s string) bool {
// 生成返回错误信息 // 生成返回错误信息
func genErrMsg(sign string) string { 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 { 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 { 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]`)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册