diff --git a/agent/go.mod b/agent/go.mod index 567f762..8b6e7d0 100644 --- a/agent/go.mod +++ b/agent/go.mod @@ -6,6 +6,8 @@ replace github.com/yusing/go-proxy => .. replace github.com/yusing/go-proxy/socketproxy => ../socket-proxy +replace github.com/yusing/go-proxy/internal/utils => ../internal/utils + replace github.com/docker/docker => github.com/godoxy-app/docker v0.0.0-20250523125835-a2474a6ebe30 replace github.com/shirou/gopsutil/v4 => github.com/godoxy-app/gopsutil/v4 v4.0.0-20250523121925-f87c3159e327 @@ -15,6 +17,7 @@ require ( github.com/rs/zerolog v1.34.0 github.com/stretchr/testify v1.10.0 github.com/yusing/go-proxy v0.0.0-00010101000000-000000000000 + github.com/yusing/go-proxy/internal/utils v0.0.0 github.com/yusing/go-proxy/socketproxy v0.0.0-00010101000000-000000000000 ) diff --git a/go.mod b/go.mod index 38af281..df26fd2 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ replace github.com/yusing/go-proxy/agent => ./agent replace github.com/yusing/go-proxy/internal/dnsproviders => ./internal/dnsproviders +replace github.com/yusing/go-proxy/internal/utils => ./internal/utils + replace github.com/coreos/go-oidc/v3 => github.com/godoxy-app/go-oidc/v3 v3.0.0-20250523122447-f078841dec22 replace github.com/docker/docker => github.com/godoxy-app/docker v0.0.0-20250523125835-a2474a6ebe30 @@ -45,7 +47,7 @@ require ( github.com/stretchr/testify v1.10.0 github.com/yusing/go-proxy/agent v0.0.0-00010101000000-000000000000 github.com/yusing/go-proxy/internal/dnsproviders v0.0.0-00010101000000-000000000000 - go.uber.org/atomic v1.11.0 + github.com/yusing/go-proxy/internal/utils v0.0.0 ) require ( @@ -219,6 +221,7 @@ require ( go.opentelemetry.io/otel v1.36.0 // indirect go.opentelemetry.io/otel/metric v1.36.0 // indirect go.opentelemetry.io/otel/trace v1.36.0 // indirect + go.uber.org/atomic v1.11.0 // indirect go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/mock v0.5.2 // indirect go.uber.org/multierr v1.11.0 // indirect @@ -226,7 +229,7 @@ require ( golang.org/x/mod v0.24.0 // indirect golang.org/x/sync v0.14.0 // indirect golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.25.0 + golang.org/x/text v0.25.0 // indirect golang.org/x/tools v0.33.0 // indirect google.golang.org/api v0.234.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250519155744-55703ea1f237 // indirect diff --git a/internal/autocert/providers.go b/internal/autocert/providers.go index dbbcb6d..222c834 100644 --- a/internal/autocert/providers.go +++ b/internal/autocert/providers.go @@ -3,7 +3,7 @@ package autocert import ( "github.com/go-acme/lego/v4/challenge" "github.com/yusing/go-proxy/internal/gperr" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type Generator func(map[string]any) (challenge.Provider, gperr.Error) @@ -16,7 +16,7 @@ func DNSProvider[CT any, PT challenge.Provider]( ) Generator { return func(opt map[string]any) (challenge.Provider, gperr.Error) { cfg := defaultCfg() - err := utils.MapUnmarshalValidate(opt, &cfg) + err := serialization.MapUnmarshalValidate(opt, &cfg) if err != nil { return nil, err } diff --git a/internal/config/types/config.go b/internal/config/types/config.go index 4460025..80fa48e 100644 --- a/internal/config/types/config.go +++ b/internal/config/types/config.go @@ -14,7 +14,7 @@ import ( maxmind "github.com/yusing/go-proxy/internal/maxmind/types" "github.com/yusing/go-proxy/internal/notif" "github.com/yusing/go-proxy/internal/proxmox" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( @@ -93,14 +93,14 @@ func HasInstance() bool { func Validate(data []byte) gperr.Error { var model Config - return utils.UnmarshalValidateYAML(data, &model) + return serialization.UnmarshalValidateYAML(data, &model) } var matchDomainsRegex = regexp.MustCompile(`^[^\.]?([\w\d\-_]\.?)+[^\.]?$`) func init() { - utils.RegisterDefaultValueFactory(DefaultConfig) - utils.MustRegisterValidation("domain_name", func(fl validator.FieldLevel) bool { + serialization.RegisterDefaultValueFactory(DefaultConfig) + serialization.MustRegisterValidation("domain_name", func(fl validator.FieldLevel) bool { domains := fl.Field().Interface().([]string) for _, domain := range domains { if !matchDomainsRegex.MatchString(domain) { @@ -109,7 +109,7 @@ func init() { } return true }) - utils.MustRegisterValidation("non_empty_docker_keys", func(fl validator.FieldLevel) bool { + serialization.MustRegisterValidation("non_empty_docker_keys", func(fl validator.FieldLevel) bool { m := fl.Field().Interface().(map[string]string) for k := range m { if k == "" { diff --git a/internal/dnsproviders/go.mod b/internal/dnsproviders/go.mod index 5506b95..65efe61 100644 --- a/internal/dnsproviders/go.mod +++ b/internal/dnsproviders/go.mod @@ -4,6 +4,8 @@ go 1.24.3 replace github.com/yusing/go-proxy => ../.. +replace github.com/yusing/go-proxy/internal/utils => ../utils + require ( github.com/go-acme/lego/v4 v4.23.1 github.com/yusing/go-proxy v0.0.0-00010101000000-000000000000 @@ -156,6 +158,7 @@ require ( github.com/vultr/govultr/v3 v3.20.0 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect + github.com/yusing/go-proxy/internal/utils v0.0.0 // indirect go.mongodb.org/mongo-driver v1.17.3 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect diff --git a/internal/docker/container.go b/internal/docker/container.go index 6044b30..07d07be 100644 --- a/internal/docker/container.go +++ b/internal/docker/container.go @@ -14,6 +14,7 @@ import ( "github.com/yusing/go-proxy/internal/gperr" idlewatcher "github.com/yusing/go-proxy/internal/idlewatcher/types" "github.com/yusing/go-proxy/internal/logging" + "github.com/yusing/go-proxy/internal/serialization" "github.com/yusing/go-proxy/internal/utils" ) @@ -224,7 +225,7 @@ func (c *Container) loadDeleteIdlewatcherLabels(helper containerHelper) { ContainerName: c.ContainerName, }, } - err := utils.MapUnmarshalValidate(cfg, idwCfg) + err := serialization.MapUnmarshalValidate(cfg, idwCfg) if err != nil { gperr.LogWarn("invalid idlewatcher config", gperr.PrependSubject(c.ContainerName, err)) } else { diff --git a/internal/logging/accesslog/config.go b/internal/logging/accesslog/config.go index e9b90d5..9ac0c5d 100644 --- a/internal/logging/accesslog/config.go +++ b/internal/logging/accesslog/config.go @@ -4,7 +4,7 @@ import ( "time" "github.com/yusing/go-proxy/internal/gperr" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( @@ -126,6 +126,6 @@ func DefaultACLLoggerConfig() *ACLLoggerConfig { } func init() { - utils.RegisterDefaultValueFactory(DefaultRequestLoggerConfig) - utils.RegisterDefaultValueFactory(DefaultACLLoggerConfig) + serialization.RegisterDefaultValueFactory(DefaultRequestLoggerConfig) + serialization.RegisterDefaultValueFactory(DefaultACLLoggerConfig) } diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 375d4dd..ec6a2bf 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -10,6 +10,8 @@ import ( "github.com/rs/zerolog" "github.com/yusing/go-proxy/internal/common" "github.com/yusing/go-proxy/internal/utils/strutils" + + zerologlog "github.com/rs/zerolog/log" ) var ( @@ -61,6 +63,8 @@ func InitLogger(out ...io.Writer) { log.SetOutput(writer) log.SetPrefix("") log.SetFlags(0) + zerolog.TimeFieldFormat = timeFmt + zerologlog.Logger = logger } func DiscardLogger() { zerolog.SetGlobalLevel(zerolog.Disabled) } diff --git a/internal/net/gphttp/reverseproxy/reverse_proxy_mod.go b/internal/net/gphttp/reverseproxy/reverse_proxy.go similarity index 100% rename from internal/net/gphttp/reverseproxy/reverse_proxy_mod.go rename to internal/net/gphttp/reverseproxy/reverse_proxy.go diff --git a/internal/notif/config.go b/internal/notif/config.go index 8bc396e..7f91c3d 100644 --- a/internal/notif/config.go +++ b/internal/notif/config.go @@ -2,7 +2,7 @@ package notif import ( "github.com/yusing/go-proxy/internal/gperr" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type NotificationConfig struct { @@ -46,5 +46,5 @@ func (cfg *NotificationConfig) UnmarshalMap(m map[string]any) (err gperr.Error) Withf("expect %s or %s", ProviderWebhook, ProviderGotify) } - return utils.MapUnmarshalValidate(m, cfg.Provider) + return serialization.MapUnmarshalValidate(m, cfg.Provider) } diff --git a/internal/notif/config_test.go b/internal/notif/config_test.go index a7afaac..68d3897 100644 --- a/internal/notif/config_test.go +++ b/internal/notif/config_test.go @@ -4,7 +4,7 @@ import ( "net/http" "testing" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" . "github.com/yusing/go-proxy/internal/utils/testing" ) @@ -181,7 +181,7 @@ func TestNotificationConfig(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var cfg NotificationConfig provider := tt.cfg["provider"] - err := utils.MapUnmarshalValidate(tt.cfg, &cfg) + err := serialization.MapUnmarshalValidate(tt.cfg, &cfg) if tt.wantErr { ExpectHasError(t, err) } else { diff --git a/internal/notif/providers.go b/internal/notif/providers.go index 84c3c41..4327242 100644 --- a/internal/notif/providers.go +++ b/internal/notif/providers.go @@ -10,12 +10,12 @@ import ( "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/logging" - "github.com/yusing/go-proxy/internal/utils" + "github.com/yusing/go-proxy/internal/serialization" ) type ( Provider interface { - utils.CustomValidator + serialization.CustomValidator GetName() string GetURL() string diff --git a/internal/utils/serialization.go b/internal/serialization/serialization.go similarity index 97% rename from internal/utils/serialization.go rename to internal/serialization/serialization.go index e540d23..54b9631 100644 --- a/internal/utils/serialization.go +++ b/internal/serialization/serialization.go @@ -1,4 +1,4 @@ -package utils +package serialization import ( "encoding/json" @@ -12,7 +12,9 @@ import ( "github.com/go-playground/validator/v10" "github.com/goccy/go-yaml" + "github.com/puzpuzpuz/xsync/v4" "github.com/yusing/go-proxy/internal/gperr" + "github.com/yusing/go-proxy/internal/utils" "github.com/yusing/go-proxy/internal/utils/functional" "github.com/yusing/go-proxy/internal/utils/strutils" ) @@ -40,14 +42,14 @@ var ( var mapUnmarshalerType = reflect.TypeFor[MapUnmarshaller]() -var defaultValues = functional.NewMapOf[reflect.Type, func() any]() +var defaultValues = xsync.NewMapOf[reflect.Type, func() any]() func RegisterDefaultValueFactory[T any](factory func() *T) { t := reflect.TypeFor[T]() if t.Kind() == reflect.Ptr { panic("pointer of pointer") } - if defaultValues.Has(t) { + if _, ok := defaultValues.Load(t); ok { panic("default value for " + t.String() + " already registered") } defaultValues.Store(t, func() any { return factory() }) @@ -259,7 +261,7 @@ func mapUnmarshalValidate(src SerializedObject, dst any, checkValidateTag bool) errs.Add(err.Subject(k)) } } else { - errs.Add(ErrUnknownField.Subject(k).With(gperr.DoYouMean(NearestField(k, mapping)))) + errs.Add(ErrUnknownField.Subject(k).With(gperr.DoYouMean(utils.NearestField(k, mapping)))) } } if hasValidateTag && checkValidateTag { diff --git a/internal/utils/serialization_test.go b/internal/serialization/serialization_test.go similarity index 99% rename from internal/utils/serialization_test.go rename to internal/serialization/serialization_test.go index 6a08779..d067f81 100644 --- a/internal/utils/serialization_test.go +++ b/internal/serialization/serialization_test.go @@ -1,4 +1,4 @@ -package utils +package serialization import ( "reflect" diff --git a/internal/utils/validation.go b/internal/serialization/validation.go similarity index 95% rename from internal/utils/validation.go rename to internal/serialization/validation.go index 490c348..0b222f2 100644 --- a/internal/utils/validation.go +++ b/internal/serialization/validation.go @@ -1,4 +1,4 @@ -package utils +package serialization import ( "github.com/go-playground/validator/v10" diff --git a/internal/utils/go.mod b/internal/utils/go.mod new file mode 100644 index 0000000..6ccf74c --- /dev/null +++ b/internal/utils/go.mod @@ -0,0 +1,21 @@ +module github.com/yusing/go-proxy/internal/utils + +go 1.24.3 + +require ( + github.com/goccy/go-yaml v1.17.1 + github.com/puzpuzpuz/xsync/v4 v4.1.0 + github.com/rs/zerolog v1.34.0 + github.com/stretchr/testify v1.10.0 + go.uber.org/atomic v1.11.0 + golang.org/x/text v0.25.0 +) + +require ( + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + golang.org/x/sys v0.33.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/internal/utils/go.sum b/internal/utils/go.sum new file mode 100644 index 0000000..7477df6 --- /dev/null +++ b/internal/utils/go.sum @@ -0,0 +1,36 @@ +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY= +github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/puzpuzpuz/xsync/v4 v4.1.0 h1:x9eHRl4QhZFIPJ17yl4KKW9xLyVWbb3/Yq4SXpjF71U= +github.com/puzpuzpuz/xsync/v4 v4.1.0/go.mod h1:VJDmTCJMBt8igNxnkQd86r+8KUeN1quSfNKu5bLYFQo= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= +golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/utils/io.go b/internal/utils/io.go index 5d8488a..33881fc 100644 --- a/internal/utils/io.go +++ b/internal/utils/io.go @@ -8,7 +8,6 @@ import ( "sync" "syscall" - "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/utils/synk" ) @@ -91,20 +90,20 @@ func NewBidirectionalPipe(ctx context.Context, rw1 io.ReadWriteCloser, rw2 io.Re } } -func (p BidirectionalPipe) Start() gperr.Error { +func (p BidirectionalPipe) Start() error { var wg sync.WaitGroup wg.Add(2) - b := gperr.NewBuilder("bidirectional pipe error") + var srcErr, dstErr error go func() { - b.Add(p.pSrcDst.Start()) + srcErr = p.pSrcDst.Start() wg.Done() }() go func() { - b.Add(p.pDstSrc.Start()) + dstErr = p.pDstSrc.Start() wg.Done() }() wg.Wait() - return b.Error() + return errors.Join(srcErr, dstErr) } type httpFlusher interface { @@ -143,30 +142,18 @@ func CopyClose(dst *ContextWriter, src *ContextReader) (err error) { wCloser, wCanClose := dst.Writer.(io.Closer) rCloser, rCanClose := src.Reader.(io.Closer) if wCanClose || rCanClose { - if src.ctx == dst.ctx { - go func() { - <-src.ctx.Done() - if wCanClose { - wCloser.Close() - } - if rCanClose { - rCloser.Close() - } - }() - } else { - if wCloser != nil { - go func() { - <-src.ctx.Done() - wCloser.Close() - }() + go func() { + select { + case <-src.ctx.Done(): + case <-dst.ctx.Done(): } - if rCloser != nil { - go func() { - <-dst.ctx.Done() - rCloser.Close() - }() + if rCanClose { + defer rCloser.Close() } - } + if wCanClose { + defer wCloser.Close() + } + }() } flusher := getHTTPFlusher(dst.Writer) canFlush := flusher != nil diff --git a/internal/utils/pool/pool.go b/internal/utils/pool/pool.go index 7abe4bc..84056e9 100644 --- a/internal/utils/pool/pool.go +++ b/internal/utils/pool/pool.go @@ -4,7 +4,7 @@ import ( "sort" "github.com/puzpuzpuz/xsync/v4" - "github.com/yusing/go-proxy/internal/logging" + "github.com/rs/zerolog/log" ) type ( @@ -29,12 +29,12 @@ func (p Pool[T]) Name() string { func (p Pool[T]) Add(obj T) { p.checkExists(obj.Key()) p.m.Store(obj.Key(), obj) - logging.Info().Msgf("%s: added %s", p.name, obj.Name()) + log.Info().Msgf("%s: added %s", p.name, obj.Name()) } func (p Pool[T]) Del(obj T) { p.m.Delete(obj.Key()) - logging.Info().Msgf("%s: removed %s", p.name, obj.Name()) + log.Info().Msgf("%s: removed %s", p.name, obj.Name()) } func (p Pool[T]) Get(key string) (T, bool) { diff --git a/internal/utils/pool/pool_debug.go b/internal/utils/pool/pool_debug.go index 6ab84f6..bb444db 100644 --- a/internal/utils/pool/pool_debug.go +++ b/internal/utils/pool/pool_debug.go @@ -5,11 +5,11 @@ package pool import ( "runtime/debug" - "github.com/yusing/go-proxy/internal/logging" + "github.com/rs/zerolog/log" ) func (p Pool[T]) checkExists(key string) { if _, ok := p.m.Load(key); ok { - logging.Warn().Msgf("%s: key %s already exists\nstacktrace: %s", p.name, key, string(debug.Stack())) + log.Warn().Msgf("%s: key %s already exists\nstacktrace: %s", p.name, key, string(debug.Stack())) } } diff --git a/internal/utils/synk/pool.go b/internal/utils/synk/pool.go index 11e282a..f9af215 100644 --- a/internal/utils/synk/pool.go +++ b/internal/utils/synk/pool.go @@ -6,7 +6,7 @@ import ( "sync/atomic" "time" - "github.com/yusing/go-proxy/internal/logging" + "github.com/rs/zerolog/log" ) type BytesPool struct { @@ -140,6 +140,6 @@ func dropBuffers() { checks++ } if count > 0 { - logging.Debug().Int("dropped", count).Int("size", droppedSize).Msg("dropped buffers from pool") + log.Debug().Int("dropped", count).Int("size", droppedSize).Msg("dropped buffers from pool") } } diff --git a/internal/utils/testing/expect.go b/internal/utils/testing/expect.go index a87ddaa..4455d7c 100644 --- a/internal/utils/testing/expect.go +++ b/internal/utils/testing/expect.go @@ -2,14 +2,16 @@ package expect import ( "os" + "strings" "testing" "github.com/stretchr/testify/require" - "github.com/yusing/go-proxy/internal/common" ) +var isTest = strings.HasSuffix(os.Args[0], ".test") + func init() { - if common.IsTest { + if isTest { // force verbose output os.Args = append([]string{os.Args[0], "-test.v"}, os.Args[1:]...) } diff --git a/internal/utils/testing/testing.go b/internal/utils/testing/testing.go index 52f118c..13411c3 100644 --- a/internal/utils/testing/testing.go +++ b/internal/utils/testing/testing.go @@ -1,19 +1,11 @@ package expect import ( - "os" "testing" "github.com/stretchr/testify/require" - "github.com/yusing/go-proxy/internal/common" ) -func init() { - if common.IsTest { - os.Args = append([]string{os.Args[0], "-test.v"}, os.Args[1:]...) - } -} - func ExpectNoError(t *testing.T, err error) { t.Helper() require.NoError(t, err) diff --git a/internal/utils/time_now.go b/internal/utils/time_now.go index 8b5e155..00bcff3 100644 --- a/internal/utils/time_now.go +++ b/internal/utils/time_now.go @@ -3,7 +3,6 @@ package utils import ( "time" - "github.com/yusing/go-proxy/internal/task" "go.uber.org/atomic" ) @@ -38,8 +37,6 @@ func init() { go func() { for { select { - case <-task.RootContext().Done(): - return case <-timeNowTicker.C: shouldCallTimeNow.Store(true) }