refactor: introduce Wire dependency injection and interface-based architecture

- Add Google Wire for compile-time dependency injection
- Replace concrete service types with interfaces across handlers
- Remove global state (DB, cache) in favor of constructor injection
- Split monolithic files into focused modules:
  - config: separate files for each config domain
  - dto: converters split by domain (user, post, message, group)
  - cache: separate metrics.go and redis_cache.go
- Introduce unified apperrors package with string-based error codes
- Add transaction support with context-aware repository methods
- Upgrade golang.org/x/crypto from 0.17.0 to 0.26.0
This commit is contained in:
2026-03-13 09:38:18 +08:00
parent 1216423350
commit cf36b1350d
49 changed files with 2571 additions and 2218 deletions

View File

@@ -8,6 +8,7 @@ import (
"strings"
"carrot_bbs/internal/dto"
apperrors "carrot_bbs/internal/errors"
"carrot_bbs/internal/model"
"carrot_bbs/internal/repository"
@@ -15,10 +16,10 @@ import (
)
var (
ErrInvalidSchedulePayload = &ServiceError{Code: 400, Message: "invalid schedule payload"}
ErrScheduleCourseNotFound = &ServiceError{Code: 404, Message: "schedule course not found"}
ErrScheduleForbidden = &ServiceError{Code: 403, Message: "forbidden schedule operation"}
ErrScheduleColorDuplicated = &ServiceError{Code: 400, Message: "course color already used"}
ErrInvalidSchedulePayload = apperrors.ErrInvalidSchedulePayload
ErrScheduleCourseNotFound = apperrors.ErrScheduleCourseNotFound
ErrScheduleForbidden = apperrors.ErrScheduleForbidden
ErrScheduleColorDuplicated = apperrors.ErrScheduleColorDuplicated
)
var hexColorRegex = regexp.MustCompile(`^#[0-9A-F]{6}$`)