enhance: nginx log

This commit is contained in:
Jacky 2025-04-02 18:56:15 +08:00
parent 2e284c5aa1
commit 56f4e5b87f
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
24 changed files with 1685 additions and 347 deletions

View file

@ -0,0 +1,43 @@
package nginx_log
import (
"slices"
"github.com/0xJacky/Nginx-UI/internal/cache"
)
func typeToInt(t string) int {
if t == "access" {
return 0
}
return 1
}
func sortCompare(i, j *cache.NginxLogCache, key string, order string) bool {
flag := false
switch key {
case "type":
flag = typeToInt(i.Type) > typeToInt(j.Type)
default:
fallthrough
case "name":
flag = i.Name > j.Name
}
if order == "asc" {
flag = !flag
}
return flag
}
func Sort(key string, order string, configs []*cache.NginxLogCache) []*cache.NginxLogCache {
slices.SortStableFunc(configs, func(i, j *cache.NginxLogCache) int {
if sortCompare(i, j, key, order) {
return 1
}
return -1
})
return configs
}