httpsvr

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCP

func TCP(addr string, handler http.Handler) error

TCP runs an HTTP server using TCP network listener.

func TLS

func TLS(addr string, handler http.Handler, certFile, keyFile string) error

TLS runs an HTTPS server using TCP network listener.

func Unix

func Unix(unix string, handler http.Handler) error

Unix runs an HTTP server using Unix domain socket listener.

func UnixTLS

func UnixTLS(unix string, handler http.Handler, certFile, keyFile string) error

UnixTLS runs an HTTPS server using Unix domain socket listener.

Types

type Server

type Server struct {
	*http.Server
	*log.Logger
	Unix string
	Host string
	Port string
	// contains filtered or unexported fields
}

Server defines parameters for running an HTTP or HTTPS server.

func New

func New() *Server

New creates a new Server instance with default logger and error log.

func (*Server) ReadBytes added in v0.1.81

func (s *Server) ReadBytes() int64

ReadBytes returns the total number of bytes read by the listener.

func (*Server) Reload added in v0.1.81

func (s *Server) Reload() error

Reload rotates server's log and reloads TLS certificates if applicable.

func (*Server) Run

func (s *Server) Run() error

Run starts an HTTP server with graceful shutdown support.

func (*Server) RunTLS

func (s *Server) RunTLS(certFile, keyFile string) error

RunTLS starts an HTTPS server using the provided certificate and key files. Certificates are automatically reloaded based on the reload interval.

func (*Server) Serve added in v0.1.81

func (s *Server) Serve(tls bool) (err error)

Serve starts the HTTP or HTTPS server and handles graceful shutdown signals.

It listens on either a Unix domain socket (if s.Unix is set) or a TCP address. When receiving SIGHUP, the server reloads configuration or certificates. When receiving SIGINT/SIGTERM, it gracefully shuts down all connections.

func (*Server) SetLogger

func (s *Server) SetLogger(logger *log.Logger)

SetLogger sets a custom logger for both the Server and its internal http.Server.

func (*Server) SetReload

func (s *Server) SetReload(d time.Duration)

SetReload defines the certificate reload interval. Default is 24 hours if not set explicitly.

func (*Server) WriteBytes added in v0.1.81

func (s *Server) WriteBytes() int64

WriteBytes returns the total number of bytes written by the listener.

Jump to

Keyboard shortcuts

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