Skip to content

Commit 4ff909d

Browse files
committed
修lint
1 parent 739fa17 commit 4ff909d

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

niu/main.go

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,43 @@ import (
1414
)
1515

1616
var (
17-
db = &model{}
18-
globalLock sync.Mutex
19-
ErrNoBoys = errors.New("暂时没有男孩子哦")
20-
ErrNoGirls = errors.New("暂时没有女孩子哦")
21-
ErrNoNiuNiu = errors.New("你还没有牛牛呢,快去注册吧!")
22-
ErrNoNiuNiuINAuction = errors.New("拍卖行还没有牛牛呢")
23-
ErrNoMoney = errors.New("你的钱不够快去赚钱吧!")
24-
ErrAdduserNoNiuNiu = errors.New("对方还没有牛牛呢,不能🤺")
25-
ErrCannotFight = errors.New("你要和谁🤺?你自己吗?")
26-
ErrNoNiuNiuTwo = errors.New("你还没有牛牛呢,咋的你想凭空造一个啊")
27-
ErrAlreadyRegistered = errors.New("你已经注册过了")
28-
ErrInvalidPropType = errors.New("道具类别传入错误")
17+
db = &model{}
18+
globalLock sync.Mutex
19+
// ErrNoBoys 表示当前没有男孩子可用的错误。
20+
ErrNoBoys = errors.New("暂时没有男孩子哦")
21+
22+
// ErrNoGirls 表示当前没有女孩子可用的错误。
23+
ErrNoGirls = errors.New("暂时没有女孩子哦")
24+
25+
// ErrNoNiuNiu 表示用户尚未拥有牛牛的错误。
26+
ErrNoNiuNiu = errors.New("你还没有牛牛呢,快去注册吧!")
27+
28+
// ErrNoNiuNiuINAuction 表示拍卖行当前没有牛牛可用的错误。
29+
ErrNoNiuNiuINAuction = errors.New("拍卖行还没有牛牛呢")
30+
31+
// ErrNoMoney 表示用户资金不足的错误。
32+
ErrNoMoney = errors.New("你的钱不够快去赚钱吧!")
33+
34+
// ErrAdduserNoNiuNiu 表示对方尚未拥有牛牛,因此无法进行某些操作的错误。
35+
ErrAdduserNoNiuNiu = errors.New("对方还没有牛牛呢,不能🤺")
36+
37+
// ErrCannotFight 表示无法进行战斗操作的错误。
38+
ErrCannotFight = errors.New("你要和谁🤺?你自己吗?")
39+
40+
// ErrNoNiuNiuTwo 表示用户尚未拥有牛牛,无法执行特定操作的错误。
41+
ErrNoNiuNiuTwo = errors.New("你还没有牛牛呢,咋的你想凭空造一个啊")
42+
43+
// ErrAlreadyRegistered 表示用户已经注册过的错误。
44+
ErrAlreadyRegistered = errors.New("你已经注册过了")
45+
46+
// ErrInvalidPropType 表示传入的道具类别错误的错误。
47+
ErrInvalidPropType = errors.New("道具类别传入错误")
48+
49+
// ErrInvalidPropUsageScope 表示道具使用域错误的错误。
2950
ErrInvalidPropUsageScope = errors.New("道具使用域错误")
30-
ErrPropNotFound = errors.New("道具不存在")
51+
52+
// ErrPropNotFound 表示找不到指定道具的错误。
53+
ErrPropNotFound = errors.New("道具不存在")
3154
)
3255

3356
func init() {
@@ -44,6 +67,13 @@ func init() {
4467
}
4568
}
4669

70+
// DeleteWordNiuNiu ...
71+
func DeleteWordNiuNiu(gid, uid int64) error {
72+
globalLock.Lock()
73+
defer globalLock.Unlock()
74+
return db.deleteWordNiuNiu(gid, uid)
75+
}
76+
4777
// SetWordNiuNiu length > 0 就增加 , length < 0 就减小
4878
func SetWordNiuNiu(gid, uid int64, length float64) error {
4979
globalLock.Lock()
@@ -56,6 +86,7 @@ func SetWordNiuNiu(gid, uid int64, length float64) error {
5686
return db.setWordNiuNiu(gid, niu)
5787
}
5888

89+
// GetWordNiuNiu ...
5990
func GetWordNiuNiu(gid, uid int64) (float64, error) {
6091
globalLock.Lock()
6192
defer globalLock.Unlock()
@@ -64,6 +95,7 @@ func GetWordNiuNiu(gid, uid int64) (float64, error) {
6495
return niu.Length, err
6596
}
6697

98+
// GetRankingInfo 获取排行信息
6799
func GetRankingInfo(gid int64, t bool) (BaseInfos, error) {
68100
globalLock.Lock()
69101
defer globalLock.Unlock()
@@ -276,7 +308,7 @@ func Sell(gid, uid int64) (string, error) {
276308
return message, err
277309
}
278310
u := AuctionInfo{
279-
UserId: niu.UID,
311+
UserID: niu.UID,
280312
Length: niu.Length,
281313
Money: money * 2,
282314
}
@@ -286,8 +318,8 @@ func Sell(gid, uid int64) (string, error) {
286318

287319
// ShowAuction 展示牛牛拍卖行
288320
func ShowAuction(gid int64) ([]AuctionInfo, error) {
289-
db.RLock()
290-
defer db.RUnlock()
321+
globalLock.Lock()
322+
defer globalLock.Unlock()
291323
return db.getAllNiuNiuAuction(gid)
292324
}
293325

@@ -311,8 +343,8 @@ func Auction(gid, uid int64, i int) (string, error) {
311343
niu.Length = auction[i].Length
312344

313345
if auction[i].Money > 500 {
314-
niu.WeiGe = 2
315-
niu.Artifact = 2
346+
niu.WeiGe += 2
347+
niu.Artifact += 2
316348
}
317349

318350
if err = db.setWordNiuNiu(gid, niu); err != nil {
@@ -323,8 +355,8 @@ func Auction(gid, uid int64, i int) (string, error) {
323355
return "", err
324356
}
325357
if auction[i].Money > 500 {
326-
return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你%d个伟哥,%d个媚药",
327-
niu.Length, niu.WeiGe, niu.Artifact), nil
358+
return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你2个伟哥,2个媚药",
359+
niu.Length), nil
328360
}
329361
return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm", niu.Length), nil
330362
}

niu/models.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
)
1313

1414
var (
15-
DaJiaoProps = []string{"伟哥", "媚药"}
16-
JJPorps = []string{"击剑神器", "击剑神稽"}
15+
daJiaoProps = []string{"伟哥", "媚药"}
16+
jjPorps = []string{"击剑神器", "击剑神稽"}
1717
query = "WHERE UID = ?"
1818
)
1919

@@ -39,18 +39,21 @@ type userInfo struct {
3939
Buff5 int // 暂定
4040
}
4141

42+
// AuctionInfo 拍卖信息
4243
type AuctionInfo struct {
4344
ID uint
44-
UserId int64
45+
UserID int64
4546
Length float64
4647
Money int
4748
}
4849

50+
// BaseInfo ...
4951
type BaseInfo struct {
5052
UID int64
5153
Length float64
5254
}
5355

56+
// BaseInfos ...
5457
type BaseInfos []BaseInfo
5558

5659
func (m users) filter(pos bool) users {
@@ -195,7 +198,7 @@ func (u *userInfo) applyProp(props string) error {
195198

196199
func (u *userInfo) useItem(itemCount *int, errMsg string) error {
197200
if *itemCount > 0 {
198-
*itemCount -= 1
201+
*itemCount--
199202
return nil
200203
}
201204
return errors.New(errMsg)
@@ -204,8 +207,8 @@ func (u *userInfo) useItem(itemCount *int, errMsg string) error {
204207
func (u *userInfo) checkProps(props, propSort string) error {
205208

206209
validProps := map[string][]string{
207-
"dajiao": DaJiaoProps,
208-
"jj": JJPorps,
210+
"dajiao": daJiaoProps,
211+
"jj": jjPorps,
209212
}
210213

211214
// 检查是否是有效道具类别
@@ -225,9 +228,9 @@ func (u *userInfo) checkProps(props, propSort string) error {
225228
}
226229

227230
// 检查是否相反
228-
conflictingProps := DaJiaoProps
231+
conflictingProps := daJiaoProps
229232
if propSort == "dajiao" {
230-
conflictingProps = JJPorps
233+
conflictingProps = jjPorps
231234
}
232235

233236
// 如果道具属于冲突集合,返回

0 commit comments

Comments
 (0)