server

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort  = 80
	TestHTTPPort = 8080
)

Variables

This section is empty.

Functions

func GetPort

func GetPort() int

Types

type Log

type Log struct {
	Msg  string
	Args []any
}

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 New

func New(stoppable bool, logCh chan<- Log, activeDownCh chan<- int) *Server

func (*Server) NotifyForShutdownReqWhenNotIdle

func (s *Server) NotifyForShutdownReqWhenNotIdle(ch chan<- string)

func (*Server) ShutdownServer

func (s *Server) ShutdownServer()

func (*Server) StartServer

func (s *Server) StartServer(filePaths ...string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL