Documentation
¶
Index ¶
Constants ¶
View Source
const DefaultMode = ProductionMode
DefaultMode is the default mode for the server.
View Source
const ProductionMode = "production"
View Source
const TestingMode = "testing"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogLevel ¶
type LogLevel string
LogLevel represents the level of logging.
const ( // LogLevelDebug is the debug logging level. LogLevelDebug LogLevel = "debug" // LogLevelInfo is the info logging level. LogLevelInfo LogLevel = "info" // LogLevelError is the error logging level. LogLevelError LogLevel = "error" // LogLevelNone is the none logging level. LogLevelNone LogLevel = "none" )
type Options ¶
type Options struct {
Host string
Port string
URL string // optional, displayed in logs
Handler func(w http.ResponseWriter, r *http.Request)
Mode string // optional, default is production, can be development or testing
LogLevel LogLevel // optional, default is "info", can be "debug", "info", "error", or "none"
// ShutdownChan is an optional channel that Start listens on for shutdown
// signals. If nil, an internal buffered channel is created. Providing a
// channel allows callers (and tests) to trigger shutdown programmatically
// by sending a signal to it. Real OS signals (SIGINT, SIGTERM) are also
// forwarded to this channel via signal.Notify.
ShutdownChan chan os.Signal
}
Options represents the configuration for the web server.
type Server ¶
func Start ¶
Start starts the web server at the specified host and port and listens for incoming requests. It blocks until a shutdown signal (SIGINT or SIGTERM) is received, then gracefully shuts the server down.
Example:
websrv.Start(websrv.Options{
Host: "localhost",
Port: "8080",
Handler: func(w http.ResponseWriter, r *http.Request) {},
Mode: websrv.ProductionMode,
})
Parameters: - options: the server configuration (see Options)
Returns: - server: the *Server instance (nil if shutdown failed) - err: a non-nil error only if graceful shutdown fails
Click to show internal directories.
Click to hide internal directories.