refactor: standardize response types across controllers

- Updated multiple controller methods to return VoidResponse instead of generic Response[any].
- Consolidated error handling to utilize GetErrorVoidResponse for consistent error responses.
- Enhanced parameter handling in export and file management functions for improved clarity and maintainability.
- Refactored health check and login/logout methods to align with new response structure.
- Improved overall consistency in response formatting across various endpoints.
This commit is contained in:
Marvin Zhang
2025-03-16 22:25:13 +08:00
parent 700c263cfe
commit 43d1c7692b
16 changed files with 175 additions and 135 deletions

View File

@@ -4,10 +4,10 @@ import (
"fmt"
"github.com/crawlab-team/crawlab/core/interfaces"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/loopfz/gadgeto/tonic"
"github.com/gin-gonic/gin"
"github.com/loopfz/gadgeto/tonic"
"github.com/wI2L/fizz"
"sync"
)
// FizzWrapper wraps an existing Gin Engine to add OpenAPI functionality
@@ -17,9 +17,9 @@ type FizzWrapper struct {
logger interfaces.Logger
}
// NewFizzWrapper creates a new wrapper around an existing Gin Engine
// newFizzWrapper creates a new wrapper around an existing Gin Engine
// This approach ensures we don't break existing functionality
func NewFizzWrapper(engine *gin.Engine) *FizzWrapper {
func newFizzWrapper(engine *gin.Engine) *FizzWrapper {
// Create a new Fizz instance using the existing Gin engine
f := fizz.NewFromEngine(engine)
return &FizzWrapper{
@@ -116,3 +116,13 @@ func (w *FizzWrapper) buildOperationOptions(id, summary, description string, res
return opts
}
var wrapper *FizzWrapper
var wrapperOnce sync.Once
func GetFizzWrapper(app *gin.Engine) *FizzWrapper {
wrapperOnce.Do(func() {
wrapper = newFizzWrapper(app)
})
return wrapper
}