作者 郑周

优化字符串计算长度

... ... @@ -2,6 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type CreateCycleCommand struct {
... ... @@ -23,7 +24,7 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "名称最大长度40个字符")
return
}
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type UpdateCycleCommand struct {
... ... @@ -15,7 +16,7 @@ type UpdateCycleCommand struct {
}
func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
return
}
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type CreateProjectCommand struct {
... ... @@ -24,7 +25,7 @@ func (in *CreateProjectCommand) Valid(validation *validation.Validation) {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
return
}
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type UpdateProjectCommand struct {
... ... @@ -36,7 +37,7 @@ type CheckRecipientCommand struct {
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
return
}
... ...
... ... @@ -3,6 +3,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"unicode/utf8"
)
type CreateRuleCommand struct {
... ... @@ -25,12 +26,12 @@ func (in *CreateRuleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
if utf8.RuneCountInString(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
... ...
... ... @@ -3,6 +3,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"unicode/utf8"
)
type UpdateRuleCommand struct {
... ... @@ -21,12 +22,12 @@ func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "名称最大长度40个字符")
return
}
if len(in.Remark) > 100 {
if utf8.RuneCountInString(in.Remark) > 100 {
validation.SetError("remark", "备注不能超过100个字符")
return
}
... ...
... ... @@ -2,6 +2,7 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type CreateTemplateCommand struct {
... ... @@ -21,12 +22,13 @@ func (in *CreateTemplateCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
// 这个才是真正计算字符串文字长度的 utf8.RuneCountInString(in.Name)
if utf8.RuneCountInString(in.Name) > 40 {
validation.SetError("name", "模板名称最大长度40个字符")
return
}
if len(in.Describe) > 100 {
if utf8.RuneCountInString(in.Describe) > 100 {
validation.SetError("describe", "备注最大长度100个字符")
return
}
... ...
... ... @@ -20,15 +20,15 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
validation.SetError("name", "模板名称最大长度40个字符")
return
}
if len(in.Describe) > 100 {
validation.SetError("describe", "备注最大长度100个字符")
return
}
//if len(in.Name) > 40 {
// validation.SetError("name", "模板名称最大长度40个字符")
// return
//}
//
//if len(in.Describe) > 100 {
// validation.SetError("describe", "备注最大长度100个字符")
// return
//}
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "评估模板流程不能为空")
... ...
package command
import "github.com/beego/beego/v2/core/validation"
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type CreateRoleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
... ... @@ -14,7 +17,7 @@ func (in *CreateRoleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 30 {
if utf8.RuneCountInString(in.Name) > 30 {
validation.SetError("name", "角色名称最大长度30个字符")
return
}
... ...
package command
import "github.com/beego/beego/v2/core/validation"
import (
"github.com/beego/beego/v2/core/validation"
"unicode/utf8"
)
type UpdateRoleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
... ... @@ -14,7 +17,7 @@ func (in *UpdateRoleCommand) Valid(validation *validation.Validation) {
validation.SetError("companyId", "公司ID无效")
}
if len(in.Name) > 30 {
if utf8.RuneCountInString(in.Name) > 30 {
validation.SetError("name", "角色名称最大长度30个字符")
return
}
... ...