Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e8faac4
authored
Sep 20, 2024
by
liuzhifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ratio must gte 0
parent
3ef8b740
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
common/group-ratio.go
+18
-2
No files found.
common/group-ratio.go
View file @
9e8faac4
...
@@ -2,6 +2,7 @@ package common
...
@@ -2,6 +2,7 @@ package common
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
)
)
var
GroupRatio
=
map
[
string
]
float64
{
var
GroupRatio
=
map
[
string
]
float64
{
...
@@ -19,8 +20,14 @@ func GroupRatio2JSONString() string {
...
@@ -19,8 +20,14 @@ func GroupRatio2JSONString() string {
}
}
func
UpdateGroupRatioByJSONString
(
jsonStr
string
)
error
{
func
UpdateGroupRatioByJSONString
(
jsonStr
string
)
error
{
GroupRatio
=
make
(
map
[
string
]
float64
)
tempGroupRatio
:=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
GroupRatio
)
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
tempGroupRatio
)
err
=
checkGroupRatio
(
tempGroupRatio
)
if
err
!=
nil
{
return
err
}
GroupRatio
=
tempGroupRatio
return
err
}
}
func
GetGroupRatio
(
name
string
)
float64
{
func
GetGroupRatio
(
name
string
)
float64
{
...
@@ -31,3 +38,12 @@ func GetGroupRatio(name string) float64 {
...
@@ -31,3 +38,12 @@ func GetGroupRatio(name string) float64 {
}
}
return
ratio
return
ratio
}
}
func
checkGroupRatio
(
checkGroupRatio
map
[
string
]
float64
)
error
{
for
name
,
ratio
:=
range
checkGroupRatio
{
if
ratio
<
0
{
return
errors
.
New
(
"group ratio must be greater than 0: "
+
name
)
}
}
return
nil
}
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