Commit 3d7cd866 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Update WAF operation constants to use localized strings

- Change operation constants for creation and deletion from English to Chinese ("新建" and "删除").
- Update the addListenerHistory method to accept the Operation type instead of a string for better type safety and clarity in logging operations.
parent 7a0e8ca0
......@@ -177,8 +177,8 @@ const (
type Operation string
const (
OperationCreate Operation = "CREATE"
OperationDelete Operation = "DELETE"
OperationCreate Operation = "新建"
OperationDelete Operation = "删除"
)
type WafListenerHistory struct {
......
......@@ -209,7 +209,7 @@ func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*WafServ
name := fmt.Sprintf("%s-%d", req.GatewayName, req.Port)
defer func() {
_ = s.addListenerHistory(ctx, name, req.ListenerName, req.GatewayName, req.Namespace, req.RegionCode, errMsg, status, "CREATE")
_ = s.addListenerHistory(ctx, name, req.ListenerName, req.GatewayName, req.Namespace, req.RegionCode, errMsg, status, model.OperationCreate)
}()
// Create the WAF service resource
......@@ -285,7 +285,7 @@ func (s *wafService) DeleteListenerWaf(ctx context.Context, req *DeleteListenerR
name := fmt.Sprintf("%s-%d", req.GatewayName, req.Port)
defer func() {
_ = s.addListenerHistory(ctx, name, req.ListenerName, req.GatewayName, req.Namespace, req.RegionCode, errMsg, status, "DELETE")
_ = s.addListenerHistory(ctx, name, req.ListenerName, req.GatewayName, req.Namespace, req.RegionCode, errMsg, status, model.OperationDelete)
}()
client := s.clusterClientManager.GetClient(req.RegionCode)
......@@ -1309,7 +1309,7 @@ func (s *wafService) ListListenerHistory(ctx context.Context, query *WafListener
return listenerHistories, int(total), nil
}
func (s *wafService) addListenerHistory(ctx context.Context, name, listenerName, gatewayName, namespace, regionCode, description string, status int, operation string) error {
func (s *wafService) addListenerHistory(ctx context.Context, name, listenerName, gatewayName, namespace, regionCode, description string, status int, operation model.Operation) error {
listenerHistory := model.WafListenerHistory{
Name: name,
GatewayName: gatewayName,
......@@ -1317,6 +1317,8 @@ func (s *wafService) addListenerHistory(ctx context.Context, name, listenerName,
Namespace: namespace,
RegionCode: regionCode,
Description: description,
Status: model.Status(status),
Operation: operation,
}
err := s.db.WithContext(ctx).Create(&listenerHistory).Error
if err != nil {
......
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