mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
refactor: cache index
This commit is contained in:
parent
5d8d96fd4f
commit
269397e114
20 changed files with 532 additions and 364 deletions
|
@ -2,10 +2,10 @@ package nginx_log
|
|||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
)
|
||||
|
||||
// typeToInt converts log type string to a sortable integer
|
||||
// "access" = 0, "error" = 1
|
||||
func typeToInt(t string) int {
|
||||
if t == "access" {
|
||||
return 0
|
||||
|
@ -13,7 +13,9 @@ func typeToInt(t string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
func sortCompare(i, j *cache.NginxLogCache, key string, order string) bool {
|
||||
// sortCompare compares two log entries based on the specified key and order
|
||||
// Returns true if i should come after j in the sorted list
|
||||
func sortCompare(i, j *NginxLogCache, key string, order string) bool {
|
||||
flag := false
|
||||
|
||||
switch key {
|
||||
|
@ -32,8 +34,11 @@ func sortCompare(i, j *cache.NginxLogCache, key string, order string) bool {
|
|||
return flag
|
||||
}
|
||||
|
||||
func Sort(key string, order string, configs []*cache.NginxLogCache) []*cache.NginxLogCache {
|
||||
slices.SortStableFunc(configs, func(i, j *cache.NginxLogCache) int {
|
||||
// Sort sorts a list of NginxLogCache entries by the specified key and order
|
||||
// Supported keys: "type", "name"
|
||||
// Supported orders: "asc", "desc"
|
||||
func Sort(key string, order string, configs []*NginxLogCache) []*NginxLogCache {
|
||||
slices.SortStableFunc(configs, func(i, j *NginxLogCache) int {
|
||||
if sortCompare(i, j, key, order) {
|
||||
return 1
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue