fix: optimize memory usage, fix agent and code refactor (#118)

* refactor: simplify io code and make utils module independent

* fix(docker): agent and socket-proxy docker event flushing with modified reverse proxy handler

* refactor: remove unused code

* refactor: remove the use of logging module in most code

* refactor: streamline domain mismatch check in certState function

* tweak: use ecdsa p-256 for autocert

* fix(tests): update health check tests for invalid host and add case for port in host

* feat(acme): custom acme directory

* refactor: code refactor and improved context and error handling

* tweak: optimize memory usage under load

* fix(oidc): restore old user matching behavior

* docs: add ChatGPT assistant to README

---------

Co-authored-by: yusing <yusing@6uo.me>
This commit is contained in:
Yuzerion
2025-05-25 09:45:57 +08:00
committed by GitHub
parent ff08c40403
commit 4a8bd48ad5
98 changed files with 1549 additions and 555 deletions

View File

@@ -13,13 +13,14 @@ import (
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/client"
"github.com/rs/zerolog/log"
"github.com/yusing/go-proxy/agent/pkg/agent"
"github.com/yusing/go-proxy/internal/common"
config "github.com/yusing/go-proxy/internal/config/types"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/task"
)
// TODO: implement reconnect here.
type (
SharedClient struct {
*client.Client
@@ -83,7 +84,7 @@ func closeTimedOutClients() {
if atomic.LoadUint32(&c.refCount) == 0 && now-atomic.LoadInt64(&c.closedOn) > clientTTLSecs {
delete(clientMap, c.Key())
c.Client.Close()
logging.Debug().Str("host", c.DaemonHost()).Msg("docker client closed")
log.Debug().Str("host", c.DaemonHost()).Msg("docker client closed")
}
}
}
@@ -148,7 +149,7 @@ func NewClient(host string) (*SharedClient, error) {
default:
helper, err := connhelper.GetConnectionHelper(host)
if err != nil {
logging.Panic().Err(err).Msg("failed to get connection helper")
log.Panic().Err(err).Msg("failed to get connection helper")
}
if helper != nil {
httpClient := &http.Client{
@@ -189,10 +190,10 @@ func NewClient(host string) (*SharedClient, error) {
c.dial = client.Dialer()
}
if c.addr == "" {
c.addr = c.Client.DaemonHost()
c.addr = c.DaemonHost()
}
defer logging.Debug().Str("host", host).Msg("docker client initialized")
defer log.Debug().Str("host", host).Msg("docker client initialized")
clientMap[c.Key()] = c
return c, nil