Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
qiuqunfeng
waf-console
Commits
9838a846
Commit
9838a846
authored
Feb 06, 2025
by
qiuqunfeng
Browse files
create waf
parent
cb8cd6a0
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
internal/utils/cluster.go
internal/utils/cluster.go
+49
-0
internal/utils/util.go
internal/utils/util.go
+2
-2
No files found.
internal/utils/cluster.go
0 → 100644
View file @
9838a846
package
utils
import
(
"sync"
"gitlab.com/tensorsecurity-rd/waf-console/pkg/generated/clientset/versioned"
)
type
ClusterClientManager
struct
{
clients
map
[
string
]
*
versioned
.
Clientset
}
func
NewClusterClientManager
()
*
ClusterClientManager
{
return
&
ClusterClientManager
{
clients
:
make
(
map
[
string
]
*
versioned
.
Clientset
),
}
}
func
(
c
*
ClusterClientManager
)
GetClient
(
regionCode
string
)
*
versioned
.
Clientset
{
return
c
.
clients
[
regionCode
]
}
func
(
c
*
ClusterClientManager
)
AddClient
(
regionCode
string
,
client
*
versioned
.
Clientset
)
{
c
.
clients
[
regionCode
]
=
client
}
func
(
c
*
ClusterClientManager
)
RemoveClient
(
regionCode
string
)
{
delete
(
c
.
clients
,
regionCode
)
}
func
(
c
*
ClusterClientManager
)
GetAllClients
()
map
[
string
]
*
versioned
.
Clientset
{
return
c
.
clients
}
func
(
c
*
ClusterClientManager
)
GetClientByRegionCode
(
regionCode
string
)
*
versioned
.
Clientset
{
return
c
.
clients
[
regionCode
]
}
func
(
c
*
ClusterClientManager
)
ForEach
(
fn
func
(
regionCode
string
,
client
*
versioned
.
Clientset
))
{
wg
:=
sync
.
WaitGroup
{}
for
regionCode
,
client
:=
range
c
.
clients
{
wg
.
Add
(
1
)
go
func
(
regionCode
string
,
client
*
versioned
.
Clientset
)
{
defer
wg
.
Done
()
fn
(
regionCode
,
client
)
}(
regionCode
,
client
)
}
wg
.
Wait
()
}
internal/utils/util.go
View file @
9838a846
...
...
@@ -4,7 +4,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"git
la
b.com/
security-rd/go-pkg/loggin
g"
"git
hu
b.com/
rs/zerolog/lo
g"
)
const
APIVersion
=
"v1"
...
...
@@ -12,7 +12,7 @@ const APIVersion = "v1"
func
AssembleResponse
(
c
*
gin
.
Context
,
data
interface
{},
err
error
,
opts
...
ResponseDataOptionFunc
)
{
code
:=
http
.
StatusOK
if
err
!=
nil
{
log
ging
.
Get
()
.
Err
(
err
)
log
.
Error
()
.
Err
(
err
)
code
=
http
.
StatusInternalServerError
c
.
JSON
(
code
,
FailResponse
{
APIVersion
:
APIVersion
,
...
...
Prev
1
2
Next
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