Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
059813d0
Commit
059813d0
authored
Aug 16, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
00cb1b2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
2 deletions
+82
-2
mysql.go
resource/mysql/mysql.go
+2
-2
test_game_race.go
script/test_game_race.go
+80
-0
No files found.
resource/mysql/mysql.go
View file @
059813d0
...
...
@@ -51,8 +51,8 @@ func init() {
if
d
,
err
:=
Db
.
DB
();
err
==
nil
{
d
.
SetConnMaxLifetime
(
time
.
Minute
*
30
)
// 连接可复用的最大时间。
d
.
SetMaxIdleConns
(
3
00
)
// 空闲连接数
d
.
SetMaxOpenConns
(
3
00
)
// 最大连接数
d
.
SetMaxIdleConns
(
2
00
)
// 空闲连接数
d
.
SetMaxOpenConns
(
2
00
)
// 最大连接数
if
err
:=
d
.
Ping
();
err
!=
nil
{
fmt
.
Printf
(
"database ping error %v"
,
err
)
}
...
...
script/test_game_race.go
0 → 100644
View file @
059813d0
package
main
import
(
"fmt"
"git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/script/mysql"
"git.hilo.cn/hilo-common/script/utils/jwt"
"io/ioutil"
"math/rand"
"net/http"
"strings"
"time"
)
func
init
()
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
}
var
raceUserCodes
=
[]
string
{
"1000653"
,
"1000516"
,
"1000675"
,
"1000890"
,
"1000755"
,
"1000593"
,
"1000629"
,
"1000634"
,
"1000765"
,
"1000591"
,
"1000633"
,
"1000224"
,
"1000611"
,
"1000689"
,
"1000467"
,
"1000384"
,
"1000367"
,
"1000623"
}
var
raceAmounts
=
[]
int
{
10
,
100
,
1000
,
5000
}
func
main
()
{
var
users
[]
model
.
User
if
err
:=
mysql
.
TestDB
.
Model
(
model
.
User
{})
.
Where
(
"code in ?"
,
raceUserCodes
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
for
i
:=
0
;
i
<
10
;
i
++
{
go
func
()
{
for
{
times
:=
20
+
rand
.
Intn
(
30
)
for
i
:=
0
;
i
<
times
;
i
++
{
arr
:=
[]
int
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
}
rand
.
Shuffle
(
len
(
arr
),
func
(
i
,
j
int
)
{
arr
[
i
],
arr
[
j
]
=
arr
[
j
],
arr
[
i
]
})
for
_
,
id
:=
range
arr
{
if
rand
.
Intn
(
100
)
<
30
{
break
}
url
:=
"https://test.apiv1.faceline.live/v1/race/"
method
:=
"POST"
amount
:=
raceAmounts
[
rand
.
Intn
(
len
(
raceAmounts
))]
payload
:=
strings
.
NewReader
(
fmt
.
Sprintf
(
"raceId=%d&amount=%d"
,
id
,
amount
))
client
:=
&
http
.
Client
{}
req
,
err
:=
http
.
NewRequest
(
method
,
url
,
payload
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
u
:=
users
[
rand
.
Intn
(
len
(
users
))]
token
,
_
:=
jwt
.
GenerateToken
(
u
.
Id
,
u
.
ExternalId
,
"hiloApi"
)
req
.
Header
.
Add
(
"nonce"
,
"hilo"
)
req
.
Header
.
Add
(
"token"
,
token
)
req
.
Header
.
Add
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
res
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
defer
res
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
res
.
Body
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
fmt
.
Printf
(
"body:%v,uid:%v
\n
"
,
string
(
body
),
u
.
Id
)
}
}
//time.Sleep(time.Second * 55)
}
}()
}
time
.
Sleep
(
time
.
Hour
*
24
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment