feat(docker): allow specifying docker network, handle error when no network available

This commit is contained in:
yusing
2025-06-14 17:08:07 +08:00
parent 5fdb023188
commit 4825f768f3
4 changed files with 86 additions and 5 deletions

34
internal/docker/errors.go Normal file
View File

@@ -0,0 +1,34 @@
package docker
import (
"encoding/json"
"github.com/yusing/go-proxy/internal/gperr"
)
type containerError struct {
errs *gperr.Builder
}
func (e *containerError) Add(err error) {
if e.errs == nil {
e.errs = gperr.NewBuilder()
}
e.errs.Add(err)
}
func (e *containerError) Error() string {
if e.errs == nil {
return "<niL>"
}
return e.errs.String()
}
func (e *containerError) Unwrap() error {
return e.errs.Error()
}
func (e *containerError) MarshalJSON() ([]byte, error) {
err := e.errs.Error().(interface{ Plain() []byte })
return json.Marshal(string(err.Plain()))
}