refactor: 使用any替代interface{}以增强类型灵活性

This commit is contained in:
tbphp
2025-07-05 20:57:16 +08:00
parent adfaf3c1e7
commit 53bf670918
2 changed files with 4 additions and 4 deletions

View File

@@ -23,13 +23,13 @@ type Pagination struct {
// PaginatedResponse is the standard structure for all paginated API responses.
type PaginatedResponse struct {
Items interface{} `json:"items"`
Pagination Pagination `json:"pagination"`
Items any `json:"items"`
Pagination Pagination `json:"pagination"`
}
// Paginate performs pagination on a GORM query and returns a standardized response.
// It takes a Gin context, a GORM query builder, and a destination slice for the results.
func Paginate(c *gin.Context, query *gorm.DB, dest interface{}) (*PaginatedResponse, error) {
func Paginate(c *gin.Context, query *gorm.DB, dest any) (*PaginatedResponse, error) {
// 1. Get page and page size from query parameters
page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
if err != nil || page < 1 {

View File

@@ -190,7 +190,7 @@ func (s *KeyCronService) batchUpdateKeyStatus(keys []models.APIKey) {
err := s.DB.Transaction(func(tx *gorm.DB) error {
for _, key := range keys {
updates := map[string]interface{}{
updates := map[string]any{
"status": key.Status,
"error_reason": key.ErrorReason,
}