1.3 KiB
1.3 KiB
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) intotime.Time. - However, the database connection (
config/db.go) is already configured withparseTime=True. - This means the MySQL driver can automatically scan
DATETIMEcolumns directly intotime.Timestruct 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.
-
Modify
server/repositories/role_repository.go:- Update
GetRoles,GetRoleByID,GetRoleByNamefunctions. - Remove temporary
[]uint8variables forcreatedAtandupdatedAt. - Scan directly into
&role.CreatedAtand&role.UpdatedAt.
- Update
-
Modify
server/repositories/permission_repository.go:- Update
GetPermissionsandGetPermissionsByRoleIDfunctions. - Remove temporary
[]uint8variables. - Scan directly into
&permission.CreatedAtand&permission.UpdatedAt.
- Update
This will resolve all "undefined: parseTime" errors and ensure the server compiles successfully.