Commit 9838a846 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

create waf

parent cb8cd6a0
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()
}
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gitlab.com/security-rd/go-pkg/logging" "github.com/rs/zerolog/log"
) )
const APIVersion = "v1" const APIVersion = "v1"
...@@ -12,7 +12,7 @@ const APIVersion = "v1" ...@@ -12,7 +12,7 @@ const APIVersion = "v1"
func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...ResponseDataOptionFunc) { func AssembleResponse(c *gin.Context, data interface{}, err error, opts ...ResponseDataOptionFunc) {
code := http.StatusOK code := http.StatusOK
if err != nil { if err != nil {
logging.Get().Err(err) log.Error().Err(err)
code = http.StatusInternalServerError code = http.StatusInternalServerError
c.JSON(code, FailResponse{ c.JSON(code, FailResponse{
APIVersion: APIVersion, APIVersion: APIVersion,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment