mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 08:44:25 +08:00
format code
This commit is contained in:
@@ -187,10 +187,10 @@ func (a *AuthorizationsApi) TwoFactorAuthorizeByRecoveryCodeHandler(c *core.Cont
|
|||||||
return authResp, nil
|
return authResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AuthorizationsApi) getAuthResponse(token string, need2FA bool, user *models.User) (*models.AuthResponse) {
|
func (a *AuthorizationsApi) getAuthResponse(token string, need2FA bool, user *models.User) *models.AuthResponse {
|
||||||
return &models.AuthResponse{
|
return &models.AuthResponse{
|
||||||
Token : token,
|
Token: token,
|
||||||
Need2FA: need2FA,
|
Need2FA: need2FA,
|
||||||
User: user.ToUserBasicInfo(),
|
User: user.ToUserBasicInfo(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/mayswind/lab/pkg/errs"
|
"github.com/mayswind/lab/pkg/errs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DefaultApi struct {}
|
type DefaultApi struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Default = &DefaultApi{}
|
Default = &DefaultApi{}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
const EuroCentralBankExchangeRateUrl = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||||
|
|
||||||
type ExchangeRatesApi struct {}
|
type ExchangeRatesApi struct{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ExchangeRates = &ExchangeRatesApi{}
|
ExchangeRates = &ExchangeRatesApi{}
|
||||||
@@ -52,7 +52,7 @@ func (a *ExchangeRatesApi) LatestExchangeRateHandler(c *core.Context) (interface
|
|||||||
|
|
||||||
latestExchangeRateResponse.ExchangeRates = append(latestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
latestExchangeRateResponse.ExchangeRates = append(latestExchangeRateResponse.ExchangeRates, &models.LatestExchangeRate{
|
||||||
Currency: "EUR",
|
Currency: "EUR",
|
||||||
Rate: "1",
|
Rate: "1",
|
||||||
})
|
})
|
||||||
|
|
||||||
return latestExchangeRateResponse, nil
|
return latestExchangeRateResponse, nil
|
||||||
|
|||||||
@@ -156,9 +156,9 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
category := a.createNewCategoryModel(uid, &models.TransactionCategoryCreateRequest{
|
category := a.createNewCategoryModel(uid, &models.TransactionCategoryCreateRequest{
|
||||||
Name: categoryCreateReq.Name,
|
Name: categoryCreateReq.Name,
|
||||||
Type: categoryCreateReq.Type,
|
Type: categoryCreateReq.Type,
|
||||||
Icon: categoryCreateReq.Icon,
|
Icon: categoryCreateReq.Icon,
|
||||||
Color: categoryCreateReq.Color,
|
Color: categoryCreateReq.Color,
|
||||||
}, maxOrderId+1)
|
}, maxOrderId+1)
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ func (a *TransactionCategoriesApi) CategoryCreateBatchHandler(c *core.Context) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
categoriesMap[nil][i] = category
|
categoriesMap[nil][i] = category
|
||||||
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId+1
|
categoryTypeMaxOrderMap[categoryCreateReq.Type] = maxOrderId + 1
|
||||||
totalCount++
|
totalCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,9 +114,9 @@ func (a *TransactionTagsApi) TagModifyHandler(c *core.Context) (interface{}, *er
|
|||||||
}
|
}
|
||||||
|
|
||||||
newTag := &models.TransactionTag{
|
newTag := &models.TransactionTag{
|
||||||
TagId: tag.TagId,
|
TagId: tag.TagId,
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
Name: tagModifyReq.Name,
|
Name: tagModifyReq.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
if newTag.Name == tag.Name {
|
if newTag.Name == tag.Name {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{},
|
|||||||
}
|
}
|
||||||
|
|
||||||
uid := c.GetCurrentUid()
|
uid := c.GetCurrentUid()
|
||||||
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, transactionListReq.Count + 1)
|
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, transactionListReq.Count+1)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorfWithRequestId(c, "[transactions.TransactionListHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", transactionListReq.MaxTime, uid, err.Error())
|
log.ErrorfWithRequestId(c, "[transactions.TransactionListHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", transactionListReq.MaxTime, uid, err.Error())
|
||||||
@@ -236,7 +236,7 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.Context) (interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
if newTransaction.CategoryId == transaction.CategoryId &&
|
if newTransaction.CategoryId == transaction.CategoryId &&
|
||||||
newTransaction.TransactionTime / 1000 == transaction.TransactionTime / 1000 &&
|
newTransaction.TransactionTime/1000 == transaction.TransactionTime/1000 &&
|
||||||
newTransaction.SourceAccountId == transaction.SourceAccountId &&
|
newTransaction.SourceAccountId == transaction.SourceAccountId &&
|
||||||
newTransaction.DestinationAccountId == transaction.DestinationAccountId &&
|
newTransaction.DestinationAccountId == transaction.DestinationAccountId &&
|
||||||
newTransaction.SourceAmount == transaction.SourceAmount &&
|
newTransaction.SourceAmount == transaction.SourceAmount &&
|
||||||
|
|||||||
+10
-10
@@ -12,13 +12,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UsersApi struct {
|
type UsersApi struct {
|
||||||
users *services.UserService
|
users *services.UserService
|
||||||
tokens *services.TokenService
|
tokens *services.TokenService
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Users = &UsersApi{
|
Users = &UsersApi{
|
||||||
users: services.Users,
|
users: services.Users,
|
||||||
tokens: services.Tokens,
|
tokens: services.Tokens,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -37,10 +37,10 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
|||||||
userRegisterReq.Nickname = strings.TrimSpace(userRegisterReq.Nickname)
|
userRegisterReq.Nickname = strings.TrimSpace(userRegisterReq.Nickname)
|
||||||
|
|
||||||
user := &models.User{
|
user := &models.User{
|
||||||
Username: userRegisterReq.Username,
|
Username: userRegisterReq.Username,
|
||||||
Email: userRegisterReq.Email,
|
Email: userRegisterReq.Email,
|
||||||
Nickname: userRegisterReq.Nickname,
|
Nickname: userRegisterReq.Nickname,
|
||||||
Password: userRegisterReq.Password,
|
Password: userRegisterReq.Password,
|
||||||
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
|||||||
|
|
||||||
authResp := &models.AuthResponse{
|
authResp := &models.AuthResponse{
|
||||||
Need2FA: false,
|
Need2FA: false,
|
||||||
User: user.ToUserBasicInfo(),
|
User: user.ToUserBasicInfo(),
|
||||||
}
|
}
|
||||||
|
|
||||||
token, claims, err := a.tokens.CreateToken(user, c)
|
token, claims, err := a.tokens.CreateToken(user, c)
|
||||||
@@ -114,8 +114,8 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
|||||||
|
|
||||||
anythingUpdate := false
|
anythingUpdate := false
|
||||||
userNew := &models.User{
|
userNew := &models.User{
|
||||||
Uid: user.Uid,
|
Uid: user.Uid,
|
||||||
Salt: user.Salt,
|
Salt: user.Salt,
|
||||||
Rands: user.Rands,
|
Rands: user.Rands,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
|||||||
|
|
||||||
log.InfofWithRequestId(c, "[users.UserUpdateProfileHandler] user \"uid:%d\" has updated successfully", user.Uid)
|
log.InfofWithRequestId(c, "[users.UserUpdateProfileHandler] user \"uid:%d\" has updated successfully", user.Uid)
|
||||||
|
|
||||||
resp := &models.UserProfileUpdateResponse {
|
resp := &models.UserProfileUpdateResponse{
|
||||||
User: user.ToUserBasicInfo(),
|
User: user.ToUserBasicInfo(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (s *DataStore) DoTransaction(key int64, fn func(sess *xorm.Session) error)
|
|||||||
return s.Choose(key).DoTransaction(fn)
|
return s.Choose(key).DoTransaction(fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DataStore) SyncStructs(beans... interface{}) error {
|
func (s *DataStore) SyncStructs(beans ...interface{}) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for i := 0; i < len(s.databases); i++ {
|
for i := 0; i < len(s.databases); i++ {
|
||||||
@@ -36,7 +36,7 @@ func (s *DataStore) SyncStructs(beans... interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDataStore(databases... *Database) (*DataStore, error) {
|
func NewDataStore(databases ...*Database) (*DataStore, error) {
|
||||||
if len(databases) < 1 {
|
if len(databases) < 1 {
|
||||||
return nil, errs.ErrDatabaseIsNull
|
return nil, errs.ErrDatabaseIsNull
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DataStoreContainer struct {
|
type DataStoreContainer struct {
|
||||||
UserStore *DataStore
|
UserStore *DataStore
|
||||||
TokenStore *DataStore
|
TokenStore *DataStore
|
||||||
UserDataStore *DataStore
|
UserDataStore *DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type XOrmLoggerAdapter struct {
|
type XOrmLoggerAdapter struct {
|
||||||
enable bool
|
enable bool
|
||||||
logLevel settings.Level
|
logLevel settings.Level
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ func (logger XOrmLoggerAdapter) IsShowSQL() bool {
|
|||||||
|
|
||||||
func NewXOrmLoggerAdapter(showSql bool, logLevel settings.Level) xorm.Logger {
|
func NewXOrmLoggerAdapter(showSql bool, logLevel settings.Level) xorm.Logger {
|
||||||
return XOrmLoggerAdapter{
|
return XOrmLoggerAdapter{
|
||||||
enable: showSql,
|
enable: showSql,
|
||||||
logLevel: logLevel,
|
logLevel: logLevel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LogFormatter struct {
|
type LogFormatter struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
DisableLevel bool
|
DisableLevel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
const REQUEST_ID_HEADER = "X-Request-ID"
|
const REQUEST_ID_HEADER = "X-Request-ID"
|
||||||
|
|
||||||
func RequestId(config *settings.Config) core.MiddlewareHandlerFunc {
|
func RequestId(config *settings.Config) core.MiddlewareHandlerFunc {
|
||||||
return func (c *core.Context) {
|
return func(c *core.Context) {
|
||||||
if requestid.Container.Current == nil {
|
if requestid.Container.Current == nil {
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ type TransactionTagCreateRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransactionTagModifyRequest struct {
|
type TransactionTagModifyRequest struct {
|
||||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransactionTagHideRequest struct {
|
type TransactionTagHideRequest struct {
|
||||||
|
|||||||
+11
-11
@@ -63,7 +63,7 @@ func (s *TokenService) ParseToken(c *core.Context) (*jwt.Token, *core.UserTokenC
|
|||||||
claims := &core.UserTokenClaims{}
|
claims := &core.UserTokenClaims{}
|
||||||
|
|
||||||
token, err := request.ParseFromRequest(c.Request, request.AuthorizationHeaderExtractor,
|
token, err := request.ParseFromRequest(c.Request, request.AuthorizationHeaderExtractor,
|
||||||
func (token *jwt.Token) (interface{}, error) {
|
func(token *jwt.Token) (interface{}, error) {
|
||||||
uid, err := utils.StringToInt64(claims.Id)
|
uid, err := utils.StringToInt64(claims.Id)
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
@@ -205,8 +205,8 @@ func (s *TokenService) ParseFromTokenId(tokenId string) (*models.TokenRecord, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
tokenRecord := &models.TokenRecord{
|
tokenRecord := &models.TokenRecord{
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
UserTokenId: userTokenId,
|
UserTokenId: userTokenId,
|
||||||
CreatedUnixTime: createdUnixTime,
|
CreatedUnixTime: createdUnixTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +222,10 @@ func (s *TokenService) createToken(user *models.User, tokenType core.TokenType,
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
tokenRecord := &models.TokenRecord{
|
tokenRecord := &models.TokenRecord{
|
||||||
Uid: user.Uid,
|
Uid: user.Uid,
|
||||||
UserTokenId: s.getUserTokenId(),
|
UserTokenId: s.getUserTokenId(),
|
||||||
TokenType: tokenType,
|
TokenType: tokenType,
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
CreatedUnixTime: now.Unix(),
|
CreatedUnixTime: now.Unix(),
|
||||||
ExpiredUnixTime: now.Add(expiryDate).Unix(),
|
ExpiredUnixTime: now.Add(expiryDate).Unix(),
|
||||||
}
|
}
|
||||||
@@ -236,11 +236,11 @@ func (s *TokenService) createToken(user *models.User, tokenType core.TokenType,
|
|||||||
|
|
||||||
claims := &core.UserTokenClaims{
|
claims := &core.UserTokenClaims{
|
||||||
UserTokenId: utils.Int64ToString(tokenRecord.UserTokenId),
|
UserTokenId: utils.Int64ToString(tokenRecord.UserTokenId),
|
||||||
Username: user.Username,
|
Username: user.Username,
|
||||||
Type: tokenRecord.TokenType,
|
Type: tokenRecord.TokenType,
|
||||||
StandardClaims: jwt.StandardClaims{
|
StandardClaims: jwt.StandardClaims{
|
||||||
Id: utils.Int64ToString(tokenRecord.Uid),
|
Id: utils.Int64ToString(tokenRecord.Uid),
|
||||||
IssuedAt: tokenRecord.CreatedUnixTime,
|
IssuedAt: tokenRecord.CreatedUnixTime,
|
||||||
ExpiresAt: tokenRecord.ExpiredUnixTime,
|
ExpiresAt: tokenRecord.ExpiredUnixTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ func (s *TransactionCategoryService) HideCategory(uid int64, ids []int64, hidden
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
updateModel := &models.TransactionCategory{
|
updateModel := &models.TransactionCategory{
|
||||||
Hidden: hidden,
|
Hidden: hidden,
|
||||||
UpdatedUnixTime: now,
|
UpdatedUnixTime: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ func (s *TransactionCategoryService) DeleteCategory(uid int64, categoryId int64)
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
updateModel := &models.TransactionCategory{
|
updateModel := &models.TransactionCategory{
|
||||||
Deleted: true,
|
Deleted: true,
|
||||||
DeletedUnixTime: now,
|
DeletedUnixTime: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ func (s *TransactionTagService) HideTag(uid int64, ids []int64, hidden bool) err
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
updateModel := &models.TransactionTag{
|
updateModel := &models.TransactionTag{
|
||||||
Hidden: hidden,
|
Hidden: hidden,
|
||||||
UpdatedUnixTime: now,
|
UpdatedUnixTime: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, m
|
|||||||
endUnixTime := endTime.Unix()
|
endUnixTime := endTime.Unix()
|
||||||
|
|
||||||
var transactions []*models.Transaction
|
var transactions []*models.Transaction
|
||||||
err = s.UserDataDB(uid).Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<?", uid, false, startUnixTime, endUnixTime).Limit(count, count * (page - 1)).OrderBy("transaction_time desc").Find(&transactions)
|
err = s.UserDataDB(uid).Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<?", uid, false, startUnixTime, endUnixTime).Limit(count, count*(page-1)).OrderBy("transaction_time desc").Find(&transactions)
|
||||||
|
|
||||||
return transactions, err
|
return transactions, err
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ func (s *TransactionService) CreateTransaction(transaction *models.Transaction,
|
|||||||
return err
|
return err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return errs.ErrDatabaseOperationFailed
|
return errs.ErrDatabaseOperationFailed
|
||||||
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||||
return errs.ErrTooMuchTransactionInOneSecond
|
return errs.ErrTooMuchTransactionInOneSecond
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,9 +465,9 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
|||||||
|
|
||||||
has, err = sess.Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<=?", transaction.Uid, false, minTransactionTime, maxTransactionTime).OrderBy("transaction_time desc").Limit(1).Get(sameSecondLatestTransaction)
|
has, err = sess.Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<=?", transaction.Uid, false, minTransactionTime, maxTransactionTime).OrderBy("transaction_time desc").Limit(1).Get(sameSecondLatestTransaction)
|
||||||
|
|
||||||
if has && sameSecondLatestTransaction.TransactionTime < maxTransactionTime - 1 {
|
if has && sameSecondLatestTransaction.TransactionTime < maxTransactionTime-1 {
|
||||||
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
||||||
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime - 1 {
|
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||||
return errs.ErrTooMuchTransactionInOneSecond
|
return errs.ErrTooMuchTransactionInOneSecond
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,7 +634,7 @@ func (s *TransactionService) DeleteTransaction(uid int64, transactionId int64) e
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
updateModel := &models.Transaction{
|
updateModel := &models.Transaction{
|
||||||
Deleted: true,
|
Deleted: true,
|
||||||
DeletedUnixTime: now,
|
DeletedUnixTime: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package services
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"xorm.io/xorm"
|
|
||||||
"github.com/pquerna/otp"
|
"github.com/pquerna/otp"
|
||||||
"github.com/pquerna/otp/totp"
|
"github.com/pquerna/otp/totp"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
|
||||||
"github.com/mayswind/lab/pkg/datastore"
|
"github.com/mayswind/lab/pkg/datastore"
|
||||||
"github.com/mayswind/lab/pkg/errs"
|
"github.com/mayswind/lab/pkg/errs"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func StringToInt32(str string) (int, error) {
|
|||||||
return strconv.Atoi(str)
|
return strconv.Atoi(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StringTryToInt32(str string, defaultValue int) int {
|
func StringTryToInt32(str string, defaultValue int) int {
|
||||||
num, err := StringToInt32(str)
|
num, err := StringToInt32(str)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func GetMinTransactionTimeFromUnixTime(unixTime int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64 {
|
func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64 {
|
||||||
return unixTime * 1000 + 999
|
return unixTime*1000 + 999
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUnixTimeFromTransactionTime(transactionTime int64) int64 {
|
func GetUnixTimeFromTransactionTime(transactionTime int64) int64 {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package utils
|
|||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||||
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||||
HexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
HexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ func AESGCMDecrypt(key []byte, ciphertext []byte) ([]byte, error) {
|
|||||||
|
|
||||||
nonceSize := aesgcm.NonceSize()
|
nonceSize := aesgcm.NonceSize()
|
||||||
|
|
||||||
if len(ciphertext) - nonceSize <= 0 {
|
if len(ciphertext)-nonceSize <= 0 {
|
||||||
return nil, errs.ErrCiphertextInvalid
|
return nil, errs.ErrCiphertextInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
const PARENT_ACCOUNT_CURRENCY_PLACEHODLER = "---"
|
const PARENT_ACCOUNT_CURRENCY_PLACEHODLER = "---"
|
||||||
|
|
||||||
// ISO 4217
|
// ISO 4217
|
||||||
var ALL_CURRENCY_NAMES = map[string]bool {
|
var ALL_CURRENCY_NAMES = map[string]bool{
|
||||||
"AED": true, //UAE Dirham
|
"AED": true, //UAE Dirham
|
||||||
"AFN": true, //Afghani
|
"AFN": true, //Afghani
|
||||||
"ALL": true, //Lek
|
"ALL": true, //Lek
|
||||||
|
|||||||
Reference in New Issue
Block a user