refactor(util): move response helper to common/response and session logic to oauth

- Relocated generic HTTP response helpers (Response, OK, Err, etc.) from internal/util/ to a dedicated internal/common/response/ package.
- Renamed ResponseAny to Any to resolve revive stuttering warnings.
- Moved session building options and cookie headers logic from internal/util/ to internal/apps/oauth/.
- Removed all direct imports of Gin/Sessions/HTTP frameworks from internal/util/ to keep general utilities 100% pure.
- Regenerated Swagger API documentation via make swagger.
- All tests and make code-check compile and pass with 0 issues.
This commit is contained in:
ryan
2026-06-15 16:38:44 +08:00
parent b3ed94342c
commit 953af7d8db
43 changed files with 1833 additions and 1853 deletions
+16 -16
View File
@@ -4,8 +4,7 @@
package task
import (
"bytes"
import ("bytes"
"context"
"encoding/json"
"fmt"
@@ -26,7 +25,8 @@ import (
"github.com/hibiken/asynq"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
"github.com/Rain-kl/Wavelet/internal/common/response")
func setupTaskTestEnvironment(t *testing.T) func() {
_, mr, cleanup := testhelper.SetupTestEnvironment(t)
@@ -78,7 +78,7 @@ func TestListTaskTypes(t *testing.T) {
t.Errorf("expected 200 OK, got %d", w.Code)
}
var resp util.ResponseAny
var resp response.Any
_ = json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -126,7 +126,7 @@ func TestDispatchTask(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code, "Body: %s", w.Body.String())
var resp util.ResponseAny
var resp response.Any
_ = json.Unmarshal(w.Body.Bytes(), &resp)
assert.Empty(t, resp.ErrorMsg)
assert.NotNil(t, resp.Data)
@@ -150,7 +150,7 @@ func TestDispatchTask(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code, "Body: %s", w.Body.String())
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
assert.Empty(t, resp.ErrorMsg)
assert.NotNil(t, resp.Data)
@@ -168,7 +168,7 @@ func TestDispatchTask(t *testing.T) {
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
assert.Contains(t, resp.ErrorMsg, "无效的 JSON 格式")
})
@@ -185,7 +185,7 @@ func TestDispatchTask(t *testing.T) {
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
assert.Contains(t, resp.ErrorMsg, "不能为空")
})
@@ -202,7 +202,7 @@ func TestDispatchTask(t *testing.T) {
assert.Equal(t, http.StatusBadRequest, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
assert.Equal(t, InvalidTaskType, resp.ErrorMsg)
})
@@ -244,7 +244,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -261,7 +261,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -278,7 +278,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -295,7 +295,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -312,7 +312,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -355,7 +355,7 @@ func TestGetTaskExecution(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
@@ -419,7 +419,7 @@ func TestRetryTask(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
var resp response.Any
json.Unmarshal(w.Body.Bytes(), &resp)
assert.Empty(t, resp.ErrorMsg)
assert.NotNil(t, resp.Data)