diff --git a/src/models/raw_entry.go b/src/models/raw_entry.go index 3d3e0b6..8274185 100644 --- a/src/models/raw_entry.go +++ b/src/models/raw_entry.go @@ -54,15 +54,17 @@ func (e *RawEntry) FillMissingFields() bool { } } - if e.PublicPortMapping != nil && e.NetworkMode != "host" { + if isDocker && e.NetworkMode != "host" { if _, ok := e.PublicPortMapping[e.Port]; !ok { // port is not exposed, but specified // try to fallback to first public port - if len(e.PublicPortMapping) == 0 { - return false - } - for _, p := range e.PublicPortMapping { + if p, ok := F.FirstValueOf(e.PublicPortMapping); ok { e.Port = fmt.Sprint(p.PublicPort) - break + } + // ignore only if it is NOT RUNNING + // because stopped containers + // will have empty port mapping got from docker + if e.Running { + return false } } } @@ -77,9 +79,6 @@ func (e *RawEntry) FillMissingFields() bool { } else if e.Port == "443" { e.Scheme = "https" } else if isDocker { - if e.Port == "" { - return false - } if p, ok := e.PublicPortMapping[e.Port]; ok { if p.Type == "udp" { e.Scheme = "udp" @@ -87,6 +86,7 @@ func (e *RawEntry) FillMissingFields() bool { e.Scheme = "http" } } else { + // port is not exposed, no way to determine return false } } else { diff --git a/src/utils/functional/map_utils.go b/src/utils/functional/map_utils.go new file mode 100644 index 0000000..41e94da --- /dev/null +++ b/src/utils/functional/map_utils.go @@ -0,0 +1,8 @@ +package functional + +func FirstValueOf[KT comparable, VT any](m map[KT]VT) (_ VT, ok bool) { + for _, v := range m { + return v, true + } + return +}