Commit f4c66c9f authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Refactor CountAttackLogs response structure in SimpleProxy to use a custom...

Refactor CountAttackLogs response structure in SimpleProxy to use a custom Response type, improving clarity and type safety in JSON unmarshalling.
parent 931eb908
......@@ -7,8 +7,6 @@ import (
"io"
"net/http"
"net/url"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
)
type SimpleProxy struct {
......@@ -43,7 +41,16 @@ func (s *SimpleProxy) CountAttackLogs(ctx context.Context, region_code string, s
if err != nil {
return 0, err
}
var response utils.SuccessResponse
type Response struct {
APIVersion string `json:"apiVersion"`
Code string `json:"code"`
Message string `json:"message"`
StatusCode int `json:"status_code"`
Data int64 `json:"data"`
}
var response Response
if err := json.Unmarshal(body, &response); err != nil {
return 0, err
}
......@@ -52,6 +59,6 @@ func (s *SimpleProxy) CountAttackLogs(ctx context.Context, region_code string, s
return 0, fmt.Errorf("failed to count attack logs: %s", response.Message)
}
return response.Data.(int64), nil
return response.Data, 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