Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultPort = 80 TestHTTPPort = 8080 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Server ¶
type Server struct {
// file paths to be served, [K: accessID, V: filepath]
FilePaths map[uint32]string
// Once Done, the server will exit
StopCtx context.Context
// Cancel func for StopCtx
StopCtxCancel context.CancelFunc
// indicates if the server is idling or currently serving files
ActiveDowns int
// Option to let others on the same LAN to stopHandler this instance from hosting
Stoppable bool
// contains filtered or unexported fields
}
func (*Server) NotifyForShutdownReqWhenNotIdle ¶
func (*Server) ShutdownServer ¶
func (s *Server) ShutdownServer()
func (*Server) StartServer ¶
StartServer starts an HTTP/HTTPS server that serves files from Server.FilePaths. It binds to the machine's outbound IP address and handles graceful shutdown. NOTE: This must run first before MDNS entry is published as it dynamically determines the port to bind to, based on tls certificate availability. For more info see GetPort() && Server.configureServer().
Returns:
- error: An error if the server fails to start, encounters issues during shutdown, or if background tasks cannot be properly terminated.
Note:
- Uses GetOutboundIP() to determine the IP address for binding.
- Will wait up to 2 seconds for server shutdown & 5 seconds for background tasks.
Click to show internal directories.
Click to hide internal directories.