Files
nl-blogs/.trae/documents/Fix Compilation Error by Using Native Driver Time Parsing.md
2026-01-15 13:51:44 +08:00

24 lines
1.3 KiB
Markdown

# Fix Compilation Error: `undefined: parseTime`
The error occurs because the `parseTime` helper function is used in `role_repository.go` and `permission_repository.go` but is not defined in the codebase.
## Root Cause
- The code attempts to manually parse time bytes (`[]uint8`) into `time.Time`.
- However, the database connection (`config/db.go`) is already configured with `parseTime=True`.
- This means the MySQL driver can automatically scan `DATETIME` columns directly into `time.Time` struct fields.
## Solution Plan
Instead of adding the missing helper function, I will refactor the code to use the driver's built-in time parsing capabilities, which is cleaner and consistent with `user_repository.go`.
1. **Modify `server/repositories/role_repository.go`**:
- Update `GetRoles`, `GetRoleByID`, `GetRoleByName` functions.
- Remove temporary `[]uint8` variables for `createdAt` and `updatedAt`.
- Scan directly into `&role.CreatedAt` and `&role.UpdatedAt`.
2. **Modify `server/repositories/permission_repository.go`**:
- Update `GetPermissions` and `GetPermissionsByRoleID` functions.
- Remove temporary `[]uint8` variables.
- Scan directly into `&permission.CreatedAt` and `&permission.UpdatedAt`.
This will resolve all "undefined: parseTime" errors and ensure the server compiles successfully.