Documentation ¶
Index ¶
Constants ¶
View Source
const (
// default port for http: 80, or address for localhost IPv4 or IPv6 port 80
HttpAddr = ":http"
)
View Source
const ( // default port for https: 443, or address for localhost IPv4 or IPv6 port 443 HttpsPort uint16 = 443 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request)
HandlerFunc is the signature for URL handlers
type Http ¶
type Http struct { // used for [http.Server.Listen] invocation // - "tcp", "tcp4", "tcp6", "unix" or "unixpacket" Network pnet.Network // Close() ListenAndServe() ListenAndServeTLS() RegisterOnShutdown() // Serve() ServeTLS() SetKeepAlivesEnabled() Shutdown() http.Server // real-time server error stream, unbound non-blocking // - [Http.SendErr] invocations // - shutdown error ErrCh parl.NBChan[error] // near socket address, protocol is tcp Near netip.AddrPort // allows to wait for listen // - when triggered, [Http.Near] is present ListenAwaitable parl.Awaitable // allows to wait for end of listen // - end of thread launched by [Http.Listen] EndListenAwaitable parl.Awaitable // whether Listen invocation is allowed NoListen atomic.Bool // Cancel of listening set-up Cancel atomic.Pointer[context.CancelFunc] // contains filtered or unexported fields }
Http is an http server instance
- based on http.Server
- has listener thread
- all errors sent on channel
- idempotent deferrable panic-free shutdown
- awaitable, observable
func NewHttp ¶
NewHttp creates http server for default “localhost:80”
- if nearSocket.Addr is invalid, all interfaces for IPv6 if allowed, IPv4 otherwise is used
- if nearSocket.Port is zero:
- — if network is NetworkDefault: ephemeral port
- — otherwise port 80 “:http” is used
- for NetworkDefault, NetworkTCP is used
- panic for bad Network
Usage:
var s = NewHttp(netip.AdddrPort{}, pnet.NetworkTCP) s.HandleFunc("/", myHandler) defer s.Shutdown() for err := range s.Listen() {
func (*Http) HandleFunc ¶
func (s *Http) HandleFunc(pattern string, handler HandlerFunc)
HandleFunc registers a URL-handler for the server
func (*Http) Listen ¶
Listen initiates listening and returns the error channel
- can only be invoked once or panic
- errCh closes on server shutdown
- non-blocking, all errors are sent on the error channel
type Https ¶
type Https struct { Http Cert parl.CertificateDer Private crypto.Signer }
Http is an http server instance
- based on http.Server
- has listener thread
- all errors sent on channel
- idempotent deferrable panic-free shutdown
- awaitable, observable
func NewHttps ¶
func NewHttps(nearSocket netip.AddrPort, network pnet.Network, certDER parl.CertificateDer, signer crypto.Signer) (hp *Https)
NewHttp creates http server for default “localhost:443”
- if nearSocket.Addr is invalid, all interfaces for IPv6 if allowed, IPv4 otherwise is used
- if nearSocket.Port is zero:
- — if network is NetworkDefault: ephemeral port
- — otherwise port 443 “:https” is used
- for NetworkDefault, NetworkTCP is used
- panic for bad Network
Usage:
var s = NewHttps(netip.AdddrPort{}, pnet.NetworkTCP) s.HandleFunc("/", myHandler) defer s.Shutdown() for err := range s.Listen() {
Click to show internal directories.
Click to hide internal directories.