removed unnecessary mutex and locking, small refactor

This commit is contained in:
yusing
2024-11-11 06:35:31 +08:00
parent c07f2ed722
commit ae69019265
2 changed files with 9 additions and 31 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sync"
"github.com/rs/zerolog"
"github.com/yusing/go-proxy/internal/docker/idlewatcher"
@@ -28,10 +27,7 @@ type StreamRoute struct {
l zerolog.Logger
}
var (
streamRoutes = F.NewMapOf[string, *StreamRoute]()
streamRoutesMu sync.Mutex
)
var streamRoutes = F.NewMapOf[string, *StreamRoute]()
func GetStreamProxies() F.Map[string, *StreamRoute] {
return streamRoutes
@@ -62,14 +58,6 @@ func (r *StreamRoute) Start(providerSubtask task.Task) E.Error {
return nil
}
streamRoutesMu.Lock()
defer streamRoutesMu.Unlock()
if r.HealthCheck.Disable && (entry.UseLoadBalance(r) || entry.UseIdleWatcher(r)) {
r.l.Error().Msg("healthCheck.disabled cannot be false when loadbalancer or idlewatcher is enabled")
r.HealthCheck.Disable = false
}
r.task = providerSubtask
r.stream = NewStream(r)
@@ -111,6 +99,7 @@ func (r *StreamRoute) Start(providerSubtask task.Task) E.Error {
}
go r.acceptConnections()
streamRoutes.Store(string(r.Alias), r)
r.task.OnFinished("remove from route table", func() {
streamRoutes.Delete(string(r.Alias))