mirror of
https://github.com/status-im/status-go.git
synced 2026-08-27 15:11:09 +00:00
`server` was one Go package doing three unrelated jobs. Each moves to where it belongs: server/pairing/ -> services/pairing/ server_media*.go, handlers*.go, testdata/ -> services/media/ server.go, certs.go, ips.go, timeout.go, device.go, listen_*.go, servertest/ -> internal/httpserver/ MediaServer is renamed to media.Server (and NewMediaServer to media.NewServer) now that it has a package to be named against. Deliberately untouched: StatusNode.MediaServer(), which is an accessor method rather than the type, and the unrelated identifiers that only share the prefix (MediaServerImageID, MediaServerContactIcon, MediaServerEnableTLS, ...). Two identifiers had to be reassigned to make the boundary clean: - certs.go held both the generic X509/TLS helpers and the media server's process-global certificate. Split: the generic half stays in internal/httpserver, generateMediaTLSCert and PublicMediaTLSCert move to services/media. - HandlerPatternMap was declared in handlers.go but is a plain HTTP type that server.go depends on; it moves to internal/httpserver. The media server URL tests moved with the type, and reached three unexported Server fields they could touch while everything shared a package. internal/httpserver now exposes ListeningAddr() and CachedPort() (both reasonable API) plus a clearly-marked SetURLStateForTest. Nothing else crossed the boundary, and the split is one-directional: services/media and services/pairing import internal/httpserver, never the reverse. refs #7067
26 lines
852 B
Go
26 lines
852 B
Go
package httpserver
|
|
|
|
import "net"
|
|
|
|
// ListeningAddr returns the address the server is currently bound to, or nil when
|
|
// it is not listening.
|
|
func (s *Server) ListeningAddr() *net.TCPAddr {
|
|
return s.address
|
|
}
|
|
|
|
// CachedPort returns the port remembered from the last successful bind. It is what
|
|
// keeps URLs stable across ToBackground/ToForeground cycles, and is zero when nothing
|
|
// has been cached yet.
|
|
func (s *Server) CachedPort() int {
|
|
return s.cachedPort
|
|
}
|
|
|
|
// SetURLStateForTest overrides the address, cached port and config that URL
|
|
// construction reads, so that packages embedding Server can exercise URL
|
|
// building without binding a socket. Test-only; do not call it elsewhere.
|
|
func (s *Server) SetURLStateForTest(address *net.TCPAddr, cachedPort int, config *Config) {
|
|
s.address = address
|
|
s.cachedPort = cachedPort
|
|
s.config = config
|
|
}
|