优惠券相关逻辑
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"pet-house.com/business/models"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetStrDays(t *testing.T) {
|
||||
@@ -54,3 +55,21 @@ func TestMath(t *testing.T) {
|
||||
var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10)
|
||||
fmt.Println(a)
|
||||
}
|
||||
func TestMap(t *testing.T) {
|
||||
var c1 = make(map[int]models.Coupons)
|
||||
c1[1] = models.Coupons{
|
||||
Id: 1,
|
||||
Name: "111",
|
||||
GoodsSubType: 0,
|
||||
Discount: 0,
|
||||
Source: "",
|
||||
PeriodType: 0,
|
||||
Period: "",
|
||||
PeriodInfo: nil,
|
||||
ExpireTime: 0,
|
||||
CreateTime: time.Time{},
|
||||
UpdateTime: time.Time{},
|
||||
Status: 0,
|
||||
}
|
||||
print("12345", c1[2].Id)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package utils
|
||||
|
||||
import "sync"
|
||||
|
||||
// KeyedMutex 提供基于键的锁定
|
||||
type KeyedMutex struct {
|
||||
mutexes sync.Map
|
||||
}
|
||||
|
||||
// Lock 锁定指定键
|
||||
func (km *KeyedMutex) Lock(key string) {
|
||||
mu, _ := km.mutexes.LoadOrStore(key, &sync.Mutex{})
|
||||
mu.(*sync.Mutex).Lock()
|
||||
}
|
||||
|
||||
// Unlock 解锁指定键
|
||||
func (km *KeyedMutex) Unlock(key string) {
|
||||
mu, ok := km.mutexes.Load(key)
|
||||
if ok {
|
||||
mu.(*sync.Mutex).Unlock()
|
||||
km.mutexes.Delete(key)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user