mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
enhance: nginx log
This commit is contained in:
parent
2e284c5aa1
commit
56f4e5b87f
24 changed files with 1685 additions and 347 deletions
43
internal/nginx_log/log_list.go
Normal file
43
internal/nginx_log/log_list.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue