refactor: use map[string]struct{} for allowedOrderBy whitelist
Per review feedback on PR #17, comment #137: use map[string]struct{} (set semantics) instead of map[string]bool for the ORDER BY field whitelist. Updates the lookup to comma-ok idiom.
This commit is contained in:
@ -78,16 +78,16 @@ func (r *sqliteCourseRepository) List(
|
|||||||
direction = "DESC"
|
direction = "DESC"
|
||||||
}
|
}
|
||||||
|
|
||||||
allowedOrderBy := map[string]bool{
|
allowedOrderBy := map[string]struct{}{
|
||||||
"id": true,
|
"id": {},
|
||||||
"name": true,
|
"name": {},
|
||||||
"created_at": true,
|
"created_at": {},
|
||||||
"updated_at": true,
|
"updated_at": {},
|
||||||
"full_price": true,
|
"full_price": {},
|
||||||
"discount": true,
|
"discount": {},
|
||||||
"duration": true,
|
"duration": {},
|
||||||
}
|
}
|
||||||
if !allowedOrderBy[params.OrderBy] {
|
if _, ok := allowedOrderBy[params.OrderBy]; !ok {
|
||||||
return result, fmt.Errorf("invalid order by field: %s", params.OrderBy)
|
return result, fmt.Errorf("invalid order by field: %s", params.OrderBy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user