mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
enhance(wip): error handle
This commit is contained in:
parent
3f95ae5d90
commit
650196d06a
93 changed files with 5228 additions and 3738 deletions
14
internal/nginx_log/errors.go
Normal file
14
internal/nginx_log/errors.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package nginx_log
|
||||
|
||||
import "github.com/uozi-tech/cosy"
|
||||
|
||||
var (
|
||||
e = cosy.NewErrorScope("nginx_log")
|
||||
ErrLogPathIsNotUnderTheLogDirWhiteList = e.New(50001, "the log path is not under the paths in settings.NginxSettings.LogDirWhiteList")
|
||||
ErrServerIdxOutOfRange = e.New(50002, "serverIdx out of range")
|
||||
ErrDirectiveIdxOutOfRange = e.New(50003, "directiveIdx out of range")
|
||||
ErrLogDirective = e.New(50004, "directive.Params neither access_log nor error_log")
|
||||
ErrDirectiveParamsIsEmpty = e.New(50005, "directive params is empty")
|
||||
ErrErrorLogPathIsEmpty = e.New(50006, "settings.NginxLogSettings.ErrorLogPath is empty, refer to https://nginxui.com/guide/config-nginx.html for more information")
|
||||
ErrAccessLogPathIsEmpty = e.New(50007, "settings.NginxLogSettings.AccessLogPath is empty, refer to https://nginxui.com/guide/config-nginx.html for more information")
|
||||
)
|
41
internal/nginx_log/nginx_log.go
Normal file
41
internal/nginx_log/nginx_log.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package nginx_log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// IsLogPathUnderWhiteList checks if the log path is under one of the paths in LogDirWhiteList
|
||||
func IsLogPathUnderWhiteList(path string) bool {
|
||||
cacheKey := fmt.Sprintf("isLogPathUnderWhiteList:%s", path)
|
||||
res, ok := cache.Get(cacheKey)
|
||||
|
||||
// deep copy
|
||||
logDirWhiteList := append([]string{}, settings.NginxSettings.LogDirWhiteList...)
|
||||
|
||||
accessLogPath := nginx.GetAccessLogPath()
|
||||
errorLogPath := nginx.GetErrorLogPath()
|
||||
|
||||
if accessLogPath != "" {
|
||||
logDirWhiteList = append(logDirWhiteList, filepath.Dir(accessLogPath))
|
||||
}
|
||||
if errorLogPath != "" {
|
||||
logDirWhiteList = append(logDirWhiteList, filepath.Dir(errorLogPath))
|
||||
}
|
||||
|
||||
// no cache, check it
|
||||
if !ok {
|
||||
for _, whitePath := range logDirWhiteList {
|
||||
if helper.IsUnderDirectory(path, whitePath) {
|
||||
cache.Set(cacheKey, true, 0)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return res.(bool)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue