Role strings like \"faculty\", \"warden\", \"centrehead\", and \"admin\" are scattered as raw literals across multiple handler files. This makes them easy to mistype (already inconsistent — centrehead vs centre_head in different places) and impossible for the compiler to catch.
Affected locations
handlers/faculty_auth.go
SendVerificationMail(..., "faculty") — lines 68, 86
helpers.GenerateToken(..., "faculty") — line 129
c.JSON(200, gin.H{..., "role": "faculty"}) — lines 145, 221
services.SendPasswordResetMail(..., "faculty") — line 172
handlers/warden_auth.go
SendVerificationMail(..., "warden") — lines 48, 65
helpers.GenerateToken(..., "warden") — line 106
c.JSON(200, gin.H{..., "role": "warden"}) — lines 122, 199
services.SendPasswordResetMail(..., "warden") — line 150
handlers/centrehead_auth.go
SendVerificationMail(..., "centrehead") — lines 48, 65
helpers.GenerateToken(..., "centrehead") — line 106
c.JSON(200, gin.H{..., "role": "centrehead"}) — lines 122, 198
services.SendPasswordResetMail(..., "centrehead") — line 149
handlers/admin_auth.go
helpers.GenerateToken(..., "admin") — line 69
handlers/auth.go (VerifyAccount / UserProfile switch-cases)
case "faculty", case "warden", case "admin" — lines 39–43, 67–75
handlers/admin_post.go (AdminGetPost switch-cases)
case "faculty", case "warden" — lines 269, 285
Fix
Add role constants to models/ (or a shared types package):
const (
RoleFaculty = "faculty"
RoleWarden = "warden"
RoleCentreHead = "centrehead"
RoleAdmin = "admin"
)
Then replace every raw string literal above with the corresponding constant. The compiler will catch any future typo, and a rename only needs to happen in one place.
Note: centrehead_auth.go already uses "centrehead" while auth.go routes use "centre_head" in the URL path — consolidate on one canonical spelling when making this change.
Role strings like
\"faculty\",\"warden\",\"centrehead\", and\"admin\"are scattered as raw literals across multiple handler files. This makes them easy to mistype (already inconsistent —centreheadvscentre_headin different places) and impossible for the compiler to catch.Affected locations
handlers/faculty_auth.goSendVerificationMail(..., "faculty")— lines 68, 86helpers.GenerateToken(..., "faculty")— line 129c.JSON(200, gin.H{..., "role": "faculty"})— lines 145, 221services.SendPasswordResetMail(..., "faculty")— line 172handlers/warden_auth.goSendVerificationMail(..., "warden")— lines 48, 65helpers.GenerateToken(..., "warden")— line 106c.JSON(200, gin.H{..., "role": "warden"})— lines 122, 199services.SendPasswordResetMail(..., "warden")— line 150handlers/centrehead_auth.goSendVerificationMail(..., "centrehead")— lines 48, 65helpers.GenerateToken(..., "centrehead")— line 106c.JSON(200, gin.H{..., "role": "centrehead"})— lines 122, 198services.SendPasswordResetMail(..., "centrehead")— line 149handlers/admin_auth.gohelpers.GenerateToken(..., "admin")— line 69handlers/auth.go(VerifyAccount / UserProfile switch-cases)case "faculty",case "warden",case "admin"— lines 39–43, 67–75handlers/admin_post.go(AdminGetPost switch-cases)case "faculty",case "warden"— lines 269, 285Fix
Add role constants to
models/(or a sharedtypespackage):Then replace every raw string literal above with the corresponding constant. The compiler will catch any future typo, and a rename only needs to happen in one place.