refactor(middlewares): remove xsync wrapper and replace strutils.SplitLine with bytes.Line

This commit is contained in:
yusing
2025-09-13 22:33:21 +08:00
parent fbe82c3082
commit a483e15a20
3 changed files with 16 additions and 14 deletions

View File

@@ -6,13 +6,13 @@ import (
"path"
"sync"
"github.com/puzpuzpuz/xsync/v4"
"github.com/rs/zerolog/log"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/task"
U "github.com/yusing/go-proxy/internal/utils"
F "github.com/yusing/go-proxy/internal/utils/functional"
W "github.com/yusing/go-proxy/internal/watcher"
"github.com/yusing/go-proxy/internal/utils"
"github.com/yusing/go-proxy/internal/watcher"
"github.com/yusing/go-proxy/internal/watcher/events"
)
@@ -20,13 +20,13 @@ const errPagesBasePath = common.ErrorPagesBasePath
var (
setupOnce sync.Once
dirWatcher W.Watcher
fileContentMap = F.NewMapOf[string, []byte]()
dirWatcher watcher.Watcher
fileContentMap = xsync.NewMap[string, []byte](xsync.WithGrowOnly())
)
func setup() {
t := task.RootTask("error_page", false)
dirWatcher = W.NewDirectoryWatcher(t, errPagesBasePath)
dirWatcher = watcher.NewDirectoryWatcher(t, errPagesBasePath)
loadContent()
go watchDir()
}
@@ -46,13 +46,13 @@ func GetErrorPageByStatus(statusCode int) (content []byte, ok bool) {
}
func loadContent() {
files, err := U.ListFiles(errPagesBasePath, 0)
files, err := utils.ListFiles(errPagesBasePath, 0)
if err != nil {
log.Err(err).Msg("failed to list error page resources")
return
}
for _, file := range files {
if fileContentMap.Has(file) {
if _, ok := fileContentMap.Load(file); ok {
continue
}
content, err := os.ReadFile(file)