mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 13:02:33 +02:00
test default host overrid
This commit is contained in:
parent
5a18dbc34b
commit
e736fe1f1e
4 changed files with 12 additions and 2 deletions
BIN
bin/go-proxy
BIN
bin/go-proxy
Binary file not shown.
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module github.com/yusing/go-proxy
|
|||
|
||||
go 1.21.7
|
||||
|
||||
require github.com/docker/docker v25.0.3+incompatible
|
||||
require github.com/docker/docker v25.0.4+incompatible
|
||||
|
||||
require github.com/golang/glog v1.2.0
|
||||
|
||||
|
|
2
go.sum
2
go.sum
|
@ -12,6 +12,8 @@ github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK
|
|||
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/docker/docker v25.0.3+incompatible h1:D5fy/lYmY7bvZa0XTZ5/UJPljor41F+vdyJG5luQLfQ=
|
||||
github.com/docker/docker v25.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/docker v25.0.4+incompatible h1:XITZTrq+52tZyZxUOtFIahUf3aH367FLxJzt9vZeAF8=
|
||||
github.com/docker/docker v25.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
|
||||
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
|
||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
)
|
||||
|
||||
var dockerClient *client.Client
|
||||
var defaultHost = os.Getenv("DEFAULT_HOST")
|
||||
|
||||
func buildContainerRoute(container types.Container) {
|
||||
var aliases []string
|
||||
|
@ -44,7 +45,12 @@ func buildContainerRoute(container types.Container) {
|
|||
prop.Set(reflect.ValueOf(value))
|
||||
}
|
||||
}
|
||||
if config.Port == "" {
|
||||
if config.Port == "" && defaultHost != "" {
|
||||
for _, port := range container.Ports {
|
||||
config.Port = fmt.Sprintf("%d", port.PublicPort)
|
||||
break
|
||||
}
|
||||
} else if config.Port == "" {
|
||||
// usually the smaller port is the http one
|
||||
// so make it the last one to be set (if 80 or 8080 are not exposed)
|
||||
sort.Slice(container.Ports, func(i, j int) bool {
|
||||
|
@ -87,6 +93,8 @@ func buildContainerRoute(container types.Container) {
|
|||
}
|
||||
if config.Host == "" {
|
||||
switch {
|
||||
case defaultHost != "":
|
||||
config.Host = defaultHost
|
||||
case container.HostConfig.NetworkMode == "host":
|
||||
config.Host = "host.docker.internal"
|
||||
case config.LoadBalance == "true":
|
||||
|
|
Loading…
Add table
Reference in a new issue