fix docker client panic introduced in last patch

This commit is contained in:
yusing 2025-03-02 21:59:32 +08:00
parent 7bb34b8788
commit 189c870630

View file

@ -6,7 +6,7 @@ import (
docker_events "github.com/docker/docker/api/types/events" docker_events "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
D "github.com/yusing/go-proxy/internal/docker" "github.com/yusing/go-proxy/internal/docker"
E "github.com/yusing/go-proxy/internal/error" E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/watcher/events" "github.com/yusing/go-proxy/internal/watcher/events"
) )
@ -14,7 +14,7 @@ import (
type ( type (
DockerWatcher struct { DockerWatcher struct {
host string host string
client *D.SharedClient client *docker.SharedClient
} }
DockerListOptions = docker_events.ListOptions DockerListOptions = docker_events.ListOptions
) )
@ -66,6 +66,13 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
w.client.Close() w.client.Close()
}() }()
client, err := docker.ConnectClient(w.host)
if err != nil {
errCh <- E.From(err)
return
}
w.client = client
cEventCh, cErrCh := w.client.Events(ctx, options) cEventCh, cErrCh := w.client.Events(ctx, options)
for { for {