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
f7fa5fd2
authored
Jul 18, 2025
by
Calcium-Ion
Committed by
GitHub
Jul 18, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1362 from KamiPasi/patch-1
🔧
refactor(user_usable_group): enhance concurrency control with mutex…
parents
3fabcac4
2c07014f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
setting/user_usable_group.go
+17
-0
No files found.
setting/user_usable_group.go
View file @
f7fa5fd2
...
...
@@ -3,14 +3,19 @@ package setting
import
(
"encoding/json"
"one-api/common"
"sync"
)
var
userUsableGroups
=
map
[
string
]
string
{
"default"
:
"默认分组"
,
"vip"
:
"vip分组"
,
}
var
userUsableGroupsMutex
sync
.
RWMutex
func
GetUserUsableGroupsCopy
()
map
[
string
]
string
{
userUsableGroupsMutex
.
RLock
()
defer
userUsableGroupsMutex
.
RUnlock
()
copyUserUsableGroups
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
userUsableGroups
{
copyUserUsableGroups
[
k
]
=
v
...
...
@@ -19,6 +24,9 @@ func GetUserUsableGroupsCopy() map[string]string {
}
func
UserUsableGroups2JSONString
()
string
{
userUsableGroupsMutex
.
RLock
()
defer
userUsableGroupsMutex
.
RUnlock
()
jsonBytes
,
err
:=
json
.
Marshal
(
userUsableGroups
)
if
err
!=
nil
{
common
.
SysError
(
"error marshalling user groups: "
+
err
.
Error
())
...
...
@@ -27,6 +35,9 @@ func UserUsableGroups2JSONString() string {
}
func
UpdateUserUsableGroupsByJSONString
(
jsonStr
string
)
error
{
userUsableGroupsMutex
.
Lock
()
defer
userUsableGroupsMutex
.
Unlock
()
userUsableGroups
=
make
(
map
[
string
]
string
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
userUsableGroups
)
}
...
...
@@ -47,11 +58,17 @@ func GetUserUsableGroups(userGroup string) map[string]string {
}
func
GroupInUserUsableGroups
(
groupName
string
)
bool
{
userUsableGroupsMutex
.
RLock
()
defer
userUsableGroupsMutex
.
RUnlock
()
_
,
ok
:=
userUsableGroups
[
groupName
]
return
ok
}
func
GetUsableGroupDescription
(
groupName
string
)
string
{
userUsableGroupsMutex
.
RLock
()
defer
userUsableGroupsMutex
.
RUnlock
()
if
desc
,
ok
:=
userUsableGroups
[
groupName
];
ok
{
return
desc
}
...
...
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