refactor: remove unnecessary xsync.Map wrapper

- Updated agentPool, cachedAddr, fileContentMap, and lastSeenMap to use xsync.Map.
- Removed functional package and its related tests.
This commit is contained in:
yusing
2025-09-04 10:07:58 +08:00
parent 4a000316be
commit 97b6066466
10 changed files with 18 additions and 140 deletions

View File

@@ -5,16 +5,16 @@ import (
"net/http"
"github.com/go-playground/validator/v10"
"github.com/puzpuzpuz/xsync/v4"
gphttp "github.com/yusing/go-proxy/internal/net/gphttp"
nettypes "github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/serialization"
F "github.com/yusing/go-proxy/internal/utils/functional"
)
type (
cidrWhitelist struct {
CIDRWhitelistOpts
cachedAddr F.Map[string, bool] // cache for trusted IPs
cachedAddr *xsync.Map[string, bool] // cache for trusted IPs
}
CIDRWhitelistOpts struct {
Allow []*nettypes.CIDR `validate:"min=1"`
@@ -42,7 +42,7 @@ func init() {
// setup implements MiddlewareWithSetup.
func (wl *cidrWhitelist) setup() {
wl.CIDRWhitelistOpts = cidrWhitelistDefaults
wl.cachedAddr = F.NewMapOf[string, bool]()
wl.cachedAddr = xsync.NewMap[string, bool](xsync.WithPresize(100))
}
// before implements RequestModifier.

View File

@@ -6,12 +6,12 @@ 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/watcher/events"
)
@@ -21,7 +21,7 @@ const errPagesBasePath = common.ErrorPagesBasePath
var (
setupOnce sync.Once
dirWatcher W.Watcher
fileContentMap = F.NewMapOf[string, []byte]()
fileContentMap = xsync.NewMap[string, []byte](xsync.WithGrowOnly())
)
func setup() {
@@ -52,7 +52,7 @@ func loadContent() {
return
}
for _, file := range files {
if fileContentMap.Has(file) {
if _, ok := fileContentMap.Load(file); ok {
continue
}
content, err := os.ReadFile(file)