Skip to content

Commit

Permalink
feat(utils): add MinInt function for comparing integers
Browse files Browse the repository at this point in the history
Introduce a utility function MinInt to determine the minimum of
two integers. This enhances code readability and reusability by
abstracting common logic. Updated admin panel to use MinInt for
slicing log entries, improving clarity and maintainability.
  • Loading branch information
infuzu-yidisprei committed Oct 9, 2024
1 parent 9b73ad0 commit bf864f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/adminpanel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (ap *AdminPanel) GetLogEntries(ctx interface{}, maxCount uint) []*logging.L
if err != nil {
return []*logging.LogEntry{}
}
entries = entries[:min(uint(len(entries)), maxCount)]
entries = entries[:utils.MinInt(len(entries), int(maxCount))]
permissibleEntries := make([]*logging.LogEntry, 0)
for _, entry := range entries {
allowed, err := ap.PermissionChecker.HasLogViewPermission(ctx, entry.ID)
Expand Down
8 changes: 8 additions & 0 deletions internal/utils/checks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package utils

func MinInt(a, b int) int {
if a < b {
return a
}
return b
}

0 comments on commit bf864f4

Please sign in to comment.