Finish all the i18n things of code.

This commit is contained in:
zicla
2019-05-06 02:18:08 +08:00
parent e37b248c8c
commit 54c5905a58
38 changed files with 504 additions and 720 deletions

View File

@ -3,7 +3,12 @@ package rest
import (
"fmt"
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/i18n"
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
"net/http"
"regexp"
"strings"
)
const (
@ -89,3 +94,22 @@ func GetUserZipRootDir(username string) (rootDirPath string) {
return rootDirPath
}
//check matter's name. If error, panic.
func CheckMatterName(request *http.Request, name string) string {
if name == "" {
panic(result.BadRequest("name cannot be null"))
}
if strings.HasPrefix(name, " ") || strings.HasSuffix(name, " ") {
panic(result.BadRequest("name cannot start with or end with space"))
}
if m, _ := regexp.MatchString(MATTER_NAME_PATTERN, name); m {
panic(result.BadRequestI18n(request, i18n.MatterNameContainSpecialChars))
}
if len(name) > MATTER_NAME_MAX_LENGTH {
panic(result.BadRequestI18n(request, i18n.MatterNameLengthExceedLimit, len(name), MATTER_NAME_MAX_LENGTH))
}
return name
}