完成部分翻译功能
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/model"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/translator"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/auth"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/email"
|
||||
@@ -21,8 +21,8 @@ var CompanyKey = "vestmore-bjwl"
|
||||
// app_market: string;
|
||||
// lang: string;
|
||||
// token: string;
|
||||
func BaseGetToken(ctx *gin.Context, param *BaseGetTokenParam) (resp *basic.Response) {
|
||||
ctx.ShouldBind(param)
|
||||
func BaseGetToken(ctx *ActionContext[BaseGetTokenParam]) (resp *basic.Response) {
|
||||
|
||||
// model.Models.KillaraCustomerModel.Find()
|
||||
log.Println()
|
||||
|
||||
@@ -43,28 +43,28 @@ func BaseGetToken(ctx *gin.Context, param *BaseGetTokenParam) (resp *basic.Respo
|
||||
// app_market: uint64;
|
||||
// email: string;
|
||||
// timestamp: int64;
|
||||
func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWithTelephonePasswordParam) (resp *basic.Response) {
|
||||
func AccountLoginWithTelephonePassword(ctx *ActionContext[AccountLoginWithTelephonePasswordParam]) (resp *basic.Response) {
|
||||
// ctx.ShouldBind()
|
||||
// model.Models.KillaraCustomerModel.Find()
|
||||
|
||||
if param.CountryCode == "" {
|
||||
if ctx.Param.CountryCode == "" {
|
||||
resp.ErrorMsg(1, "country_code 参数缺失")
|
||||
return
|
||||
|
||||
}
|
||||
if param.Telephone == "" {
|
||||
if ctx.Param.Telephone == "" {
|
||||
resp.ErrorMsg(1, "telephone 参数缺失")
|
||||
return
|
||||
}
|
||||
|
||||
if param.Password == "" {
|
||||
if ctx.Param.Password == "" {
|
||||
resp.ErrorMsg(1, "password 参数缺失")
|
||||
return
|
||||
}
|
||||
|
||||
telephone := strings.TrimSpace(param.Telephone)
|
||||
password := strings.TrimSpace(param.Password)
|
||||
countryCode := strings.TrimSpace(param.CountryCode)
|
||||
telephone := strings.TrimSpace(ctx.Param.Telephone)
|
||||
password := strings.TrimSpace(ctx.Param.Password)
|
||||
countryCode := strings.TrimSpace(ctx.Param.CountryCode)
|
||||
|
||||
// 假设 modelCustomer 和 modelCustomerToken 是对应的服务接口
|
||||
|
||||
@@ -85,52 +85,50 @@ func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWith
|
||||
}
|
||||
|
||||
if customer == nil {
|
||||
return resp.ErrorMsg(1, "账号未注册")
|
||||
return resp.ErrorTrCode(ctx, translator.AccountNotRegistered)
|
||||
}
|
||||
|
||||
if *customer.CountryCode != countryCode {
|
||||
return resp.ErrorMsg(1, "电话号码国家不正确")
|
||||
return resp.ErrorTrCode(ctx, translator.PhoneNumberCountryIncorrect)
|
||||
}
|
||||
|
||||
if *customer.Status != 1 {
|
||||
return resp.ErrorMsg(1, "账号已禁用,无法登录")
|
||||
return resp.ErrorTrCode(ctx, translator.AccountDisabledNotLogin)
|
||||
}
|
||||
|
||||
if !auth.CheckPassword(*customer.Password, *customer.Salt, *customer.RandomPassword, password) {
|
||||
return resp.ErrorMsg(1, "账号或密码错误")
|
||||
return resp.ErrorTrCode(ctx, translator.AccountOrPasswordLoginFailed)
|
||||
}
|
||||
|
||||
customerID := *customer.CustomerId
|
||||
|
||||
err = model.Models.KillaraCustomerTokenModel.UpdateTokenCustomerID(param.Token, customerID)
|
||||
err = model.Models.KillaraCustomerTokenModel.UpdateTokenCustomerID(ctx.Param.Token, customerID)
|
||||
if err != nil {
|
||||
return resp.ErrorMsg(1, err.Error())
|
||||
}
|
||||
|
||||
var deviceCode string
|
||||
if param.Device != "" {
|
||||
deviceCode = param.Device
|
||||
if ctx.Param.Device != "" {
|
||||
deviceCode = ctx.Param.Device
|
||||
}
|
||||
|
||||
var version string
|
||||
if param.Version != "" {
|
||||
version = param.Version
|
||||
if ctx.Param.Version != "" {
|
||||
version = ctx.Param.Version
|
||||
}
|
||||
|
||||
var ip string
|
||||
addr := strings.Split(ctx.Request.RemoteAddr, ":")
|
||||
addr := strings.Split(ctx.GinCtx.Request.RemoteAddr, ":")
|
||||
if len(addr) > 0 {
|
||||
ip = addr[0]
|
||||
}
|
||||
|
||||
log.Println(deviceCode, version, ip)
|
||||
|
||||
data := &model.KillaraCustomerDevice{
|
||||
CustomerId: &customerID,
|
||||
Device: &deviceCode,
|
||||
Version: &version,
|
||||
Ip: &ip,
|
||||
AppMarket: ¶m.AppMarket,
|
||||
AppMarket: &ctx.Param.AppMarket,
|
||||
Date: basic.TimePtr(time.Now()),
|
||||
}
|
||||
|
||||
@@ -143,14 +141,7 @@ func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWith
|
||||
|
||||
// // 假设 clearDuplicateToken 是对应的服务接口
|
||||
// clearDuplicateToken(customerID, param.Token)
|
||||
model.Models.KillaraCustomerTokenModel.ClearDuplicateToken(customerID, param.Token, 1)
|
||||
|
||||
// return map[string]interface{}{
|
||||
// "success": true,
|
||||
// "error_code": 0,
|
||||
// "error_text": "",
|
||||
// "data": make(map[string]interface{}),
|
||||
// }, nil
|
||||
model.Models.KillaraCustomerTokenModel.ClearDuplicateToken(customerID, ctx.Param.Token, 1)
|
||||
|
||||
// log.Println(param)
|
||||
return resp.Success()
|
||||
@@ -162,7 +153,7 @@ func AccountLoginWithTelephonePassword(ctx *gin.Context, param *AccountLoginWith
|
||||
// country_code?: string;
|
||||
// telephone?: string;
|
||||
// token: string;
|
||||
func AccountRegisterSmsCode(ctx *gin.Context, param *AccountRegisterSmsCodeParam) (resp *basic.Response) {
|
||||
func AccountRegisterSmsCode(ctx *ActionContext[AccountRegisterSmsCodeParam]) (resp *basic.Response) {
|
||||
// ctx.ShouldBind()
|
||||
log.Println()
|
||||
return resp.Success()
|
||||
@@ -174,8 +165,9 @@ func AccountRegisterSmsCode(ctx *gin.Context, param *AccountRegisterSmsCodeParam
|
||||
// country_code?: string;
|
||||
// telephone?: string;
|
||||
// token: string;
|
||||
func AccountForgetSmsCode(ctx *gin.Context, param *AccountForgetSmsCodeParam) (resp *basic.Response) {
|
||||
func AccountForgetSmsCode(ctx *ActionContext[AccountForgetSmsCodeParam]) (resp *basic.Response) {
|
||||
// ctx.ShouldBind()
|
||||
// ctx *gin.Context, param *AccountForgetSmsCodeParam
|
||||
log.Println()
|
||||
return resp.Success()
|
||||
}
|
||||
@@ -195,10 +187,9 @@ type RegisterValidEmailCode struct {
|
||||
// email: string;
|
||||
// timestamp: int64;
|
||||
// token: string;
|
||||
func AccountRegisterEmailCode(ctx *gin.Context, param *AccountRegisterEmailCodeParam) (resp *basic.Response) {
|
||||
log.Println(param)
|
||||
func AccountRegisterEmailCode(ctx *ActionContext[AccountRegisterEmailCodeParam]) (resp *basic.Response) {
|
||||
|
||||
if !email.IsEmailValid(param.Email) {
|
||||
if !email.IsEmailValid(ctx.Param.Email) {
|
||||
return resp.Error(basic.ErrEmailFormat)
|
||||
}
|
||||
|
||||
@@ -207,8 +198,8 @@ func AccountRegisterEmailCode(ctx *gin.Context, param *AccountRegisterEmailCodeP
|
||||
code := auth.GenerateVerificationCode()
|
||||
codetoken := &RegisterValidEmailCode{
|
||||
Code: code,
|
||||
Email: param.Email,
|
||||
AppMarket: param.AppMarket,
|
||||
Email: ctx.Param.Email,
|
||||
AppMarket: ctx.Param.AppMarket,
|
||||
}
|
||||
tokenstr, err := gcm.Encrypt(codetoken)
|
||||
if err != nil {
|
||||
@@ -228,7 +219,7 @@ func AccountRegisterEmailCode(ctx *gin.Context, param *AccountRegisterEmailCodeP
|
||||
// new_password: string;
|
||||
// old_password: string;
|
||||
// token?: string;
|
||||
func MemberAlterPassword(ctx *gin.Context, param *MemberAlterPasswordParam) (resp *basic.Response) {
|
||||
func MemberAlterPassword(ctx *ActionContext[MemberAlterPasswordParam]) (resp *basic.Response) {
|
||||
// ctx.ShouldBind()
|
||||
log.Println()
|
||||
return resp.Success()
|
||||
@@ -242,12 +233,82 @@ func MemberAlterPassword(ctx *gin.Context, param *MemberAlterPasswordParam) (res
|
||||
// action: string;
|
||||
// device: string;
|
||||
// version: string;
|
||||
// app_market: int;
|
||||
// app_market: uint64;
|
||||
// email: string;
|
||||
// timestamp: int64;
|
||||
// token: string;
|
||||
func AccountLoginWithEmailPassword(ctx *gin.Context, param *AccountLoginWithEmailPasswordParam) (resp *basic.Response) {
|
||||
func AccountLoginWithEmailPassword(ctx *ActionContext[AccountLoginWithEmailPasswordParam]) (resp *basic.Response) {
|
||||
|
||||
if ctx.Param.Email == "" {
|
||||
return resp.ErrorMsg(1, "email 参数缺失")
|
||||
}
|
||||
|
||||
if ctx.Param.Password == "" {
|
||||
return resp.ErrorMsg(1, "password 参数缺失")
|
||||
}
|
||||
|
||||
email := strings.TrimSpace(ctx.Param.Email)
|
||||
password := strings.TrimSpace(ctx.Param.Password)
|
||||
|
||||
var customer *model.KillaraCustomer
|
||||
var err error
|
||||
|
||||
customer, err = model.Models.KillaraCustomerModel.GetCustomerByEmailForBackEnd(email)
|
||||
if err != nil {
|
||||
return resp.ErrorErr(1, err)
|
||||
}
|
||||
|
||||
ctx.Localize(translator.AccountNotRegistered)
|
||||
if customer == nil {
|
||||
return resp.ErrorTrCode(ctx, translator.AccountNotRegistered)
|
||||
}
|
||||
|
||||
if *customer.Status != 1 {
|
||||
return resp.ErrorTrCode(ctx, translator.AccountDisabledNotLogin)
|
||||
}
|
||||
|
||||
if !auth.CheckPassword(*customer.Password, *customer.Salt, *customer.RandomPassword, password) {
|
||||
return resp.ErrorTrCode(ctx, translator.AccountOrPasswordLoginFailed)
|
||||
}
|
||||
|
||||
customerID := *customer.CustomerId
|
||||
|
||||
err = model.Models.KillaraCustomerTokenModel.UpdateTokenCustomerID(ctx.Param.Token, customerID)
|
||||
if err != nil {
|
||||
return resp.ErrorMsg(1, err.Error())
|
||||
}
|
||||
|
||||
var deviceCode string
|
||||
if ctx.Param.Device != "" {
|
||||
deviceCode = ctx.Param.Device
|
||||
}
|
||||
|
||||
var version string
|
||||
if ctx.Param.Version != "" {
|
||||
version = ctx.Param.Version
|
||||
}
|
||||
|
||||
var ip string
|
||||
addr := strings.Split(ctx.GinCtx.Request.RemoteAddr, ":")
|
||||
if len(addr) > 0 {
|
||||
ip = addr[0]
|
||||
}
|
||||
|
||||
data := &model.KillaraCustomerDevice{
|
||||
CustomerId: &customerID,
|
||||
Device: &deviceCode,
|
||||
Version: &version,
|
||||
Ip: &ip,
|
||||
AppMarket: &ctx.Param.AppMarket,
|
||||
Date: basic.TimePtr(time.Now()),
|
||||
}
|
||||
|
||||
err = model.Models.KillaraCustomerModel.InsertCustomerDevice(data)
|
||||
if err != nil {
|
||||
return resp.ErrorErr(1, err)
|
||||
}
|
||||
|
||||
model.Models.KillaraCustomerTokenModel.ClearDuplicateToken(customerID, ctx.Param.Token, 1)
|
||||
|
||||
log.Println(param)
|
||||
return resp.Success()
|
||||
}
|
||||
|
||||
@@ -2,10 +2,40 @@ package actions
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/translator"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/basic"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
|
||||
)
|
||||
|
||||
type ActionContext[PARAM any] struct {
|
||||
Lang string
|
||||
GinCtx *gin.Context
|
||||
Param *PARAM
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) Localize(MessageID translator.TrCode) (string, error) {
|
||||
return translator.Localize(MessageID, ctx.Lang, nil)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeWithData(MessageID translator.TrCode, MessageTemplateParam any) (string, error) {
|
||||
return translator.Localize(MessageID, ctx.Lang, MessageTemplateParam)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeEx(MessageID translator.TrCode, Langs ...string) (string, error) {
|
||||
if len(Langs) == 0 {
|
||||
return translator.LocalizeEx(MessageID, nil, ctx.Lang)
|
||||
}
|
||||
return translator.LocalizeEx(MessageID, nil, Langs...)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeExWithData(MessageID translator.TrCode, MessageTemplateParam any, Langs ...string) (string, error) {
|
||||
if len(Langs) == 0 {
|
||||
return translator.LocalizeEx(MessageID, MessageTemplateParam, ctx.Lang)
|
||||
}
|
||||
return translator.LocalizeEx(MessageID, MessageTemplateParam, Langs...)
|
||||
}
|
||||
|
||||
var HandlersFuncRoutes map[string]gin.HandlerFunc = make(map[string]gin.HandlerFunc)
|
||||
|
||||
func init() {
|
||||
@@ -40,10 +70,17 @@ func AccountForgetSmsCodeHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = AccountForgetSmsCode(ctx, param)
|
||||
actx := &ActionContext[AccountForgetSmsCodeParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = AccountForgetSmsCode(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -57,7 +94,7 @@ type AccountLoginWithEmailPasswordParam struct {
|
||||
Action string `json:"action" form:"action" binding:"-"`
|
||||
Device string `json:"device" form:"device" binding:"-"`
|
||||
Version string `json:"version" form:"version" binding:"-"`
|
||||
AppMarket int `json:"app_market" form:"app_market" binding:"-"`
|
||||
AppMarket uint64 `json:"app_market" form:"app_market" binding:"-"`
|
||||
Email string `json:"email" form:"email" binding:"-"`
|
||||
Timestamp int64 `json:"timestamp" form:"timestamp" binding:"-"`
|
||||
Token string `json:"token" form:"token" binding:"-"`
|
||||
@@ -71,10 +108,17 @@ func AccountLoginWithEmailPasswordHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = AccountLoginWithEmailPassword(ctx, param)
|
||||
actx := &ActionContext[AccountLoginWithEmailPasswordParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = AccountLoginWithEmailPassword(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -104,10 +148,17 @@ func AccountLoginWithTelephonePasswordHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = AccountLoginWithTelephonePassword(ctx, param)
|
||||
actx := &ActionContext[AccountLoginWithTelephonePasswordParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = AccountLoginWithTelephonePassword(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -132,10 +183,17 @@ func AccountRegisterEmailCodeHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = AccountRegisterEmailCode(ctx, param)
|
||||
actx := &ActionContext[AccountRegisterEmailCodeParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = AccountRegisterEmailCode(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -157,10 +215,17 @@ func AccountRegisterSmsCodeHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = AccountRegisterSmsCode(ctx, param)
|
||||
actx := &ActionContext[AccountRegisterSmsCodeParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = AccountRegisterSmsCode(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -182,10 +247,17 @@ func BaseGetTokenHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = BaseGetToken(ctx, param)
|
||||
actx := &ActionContext[BaseGetTokenParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = BaseGetToken(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
@@ -208,10 +280,17 @@ func MemberAlterPasswordHandler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
resp = MemberAlterPassword(ctx, param)
|
||||
actx := &ActionContext[MemberAlterPasswordParam]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = MemberAlterPassword(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,40 @@ package actions
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"{{.ModuleName}}/translator"
|
||||
"{{.ModuleName}}/utils/basic"
|
||||
"{{.ModuleName}}/utils/log"
|
||||
)
|
||||
|
||||
type ActionContext[PARAM any] struct {
|
||||
Lang string
|
||||
GinCtx *gin.Context
|
||||
Param *PARAM
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) Localize(MessageID translator.TrCode) (string, error) {
|
||||
return translator.Localize(MessageID, ctx.Lang, nil)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeWithData(MessageID translator.TrCode, MessageTemplateParam any) (string, error) {
|
||||
return translator.Localize(MessageID, ctx.Lang, MessageTemplateParam)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeEx(MessageID translator.TrCode, Langs ...string) (string, error) {
|
||||
if len(Langs) == 0 {
|
||||
return translator.LocalizeEx(MessageID, nil, ctx.Lang)
|
||||
}
|
||||
return translator.LocalizeEx(MessageID, nil, Langs...)
|
||||
}
|
||||
|
||||
func (ctx *ActionContext[PARAM]) LocalizeExWithData(MessageID translator.TrCode, MessageTemplateParam any, Langs ...string) (string, error) {
|
||||
if len(Langs) == 0 {
|
||||
return translator.LocalizeEx(MessageID, MessageTemplateParam, ctx.Lang)
|
||||
}
|
||||
return translator.LocalizeEx(MessageID, MessageTemplateParam, Langs...)
|
||||
}
|
||||
|
||||
var HandlersFuncRoutes map[string]gin.HandlerFunc = make(map[string]gin.HandlerFunc)
|
||||
|
||||
func init() {
|
||||
@@ -30,10 +60,17 @@ func {{.FuncName}}Handler(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
resp = resp.Error(basic.ErrParamParse)
|
||||
ctx.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
|
||||
actx := &ActionContext[{{.ParamStruct.ParamStructName}}]{
|
||||
Lang: basic.GetLangString(param),
|
||||
GinCtx: ctx,
|
||||
Param: param,
|
||||
}
|
||||
|
||||
resp = {{.FuncName}}(ctx, param)
|
||||
resp = {{.FuncName}}(actx)
|
||||
if resp == nil {
|
||||
resp = resp.Error(basic.ErrRespNotNil)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iapologizewhenimwrong/Vestmore_GO/translator"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
@@ -15,10 +18,26 @@ func TestMain(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCaseZero(t *testing.T) {
|
||||
var a string = ""
|
||||
var b string
|
||||
var c int = 1
|
||||
a = ""
|
||||
// lang := language.Make("zh_cn")
|
||||
log.Println(language.Make("zh_cn"))
|
||||
log.Println(language.ParseAcceptLanguage("zh_cn"))
|
||||
|
||||
tr := i18n.NewBundle(language.Chinese)
|
||||
tr.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||
tr.MustLoadMessageFile("./internal/i18n/zh_cn.toml")
|
||||
|
||||
// accept := r.Header.Get("Accept-Language")
|
||||
// i18n.NewLocalizer()
|
||||
localizer := i18n.NewLocalizer(tr, "zh_cn")
|
||||
log.Println(localizer.Localize(&i18n.LocalizeConfig{
|
||||
MessageID: "format_account_is_insufficient",
|
||||
TemplateData: map[string]any{
|
||||
"CatalogCurrency": "USDT",
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
func TestTr(t *testing.T) {
|
||||
log.Println(translator.Localize("账号未注册", "zh_cn", nil))
|
||||
|
||||
log.Println(reflect.ValueOf(a).IsZero(), reflect.ValueOf(b).IsZero(), reflect.ValueOf(c).IsZero())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user