lui

package module
v0.0.0-...-625e1a4 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 12 Imported by: 0

README

lui: Convenience wrapper around net/http

Build Status Go Documentation

For when you just want to write http handlers and call it a day.

Lui is a convenience wrapper around net/http. It provides:

  • Quick methods for setting up http/https servers
  • Graceful shutdowns
  • Optional config file support (TO BE DONE)

Why 'lui'?

'Lui' means 'lazy' in Dutch. Instead of implementing a server for each project you can be lazy and use this package.

Documentation

Overview

Package lui is a convenience wrapper around net/http. It contains functionality to quickly setup and run common http/https configurations.

Index

Constants

View Source
const (
	// DefaultReadTimeout is the read timeout used by https/https servers when no specific read timeout is provided
	DefaultReadTimeout = time.Second * 10
	// DefaultHeaderReadTimeout is the read timeout used by https/https servers when no specific read header timeout is provided
	DefaultHeaderReadTimeout = time.Second * 5
	// DefaultWriteTimeout is the read timeout used by https/https servers when no specific timeout is provided
	DefaultWriteTimeout = time.Second * 30
	// DefaultIdleTimeout is the idle timeout used by https/https servers when no specific timeout is provided
	DefaultIdleTimeout = time.Second * 60
	// DefaultShutdownTimeout is the shutdown timeout used by https/https servers when no specific timeout is provided
	DefaultShutdownTimeout = time.Second * 30
	// DefaultHTTPAddr is the default http address
	DefaultHTTPAddr = ":80"
	// DefaultHTTPSAddr is the default https address
	DefaultHTTPSAddr = ":443"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OptionFunc

type OptionFunc func(*Server) error

OptionFunc configures an option on the server

func HTTPAddr

func HTTPAddr(addr string) OptionFunc

HTTPAddr option sets the address on which the http server listens

func HTTPSAddr

func HTTPSAddr(addr string) OptionFunc

HTTPSAddr option sets the address on which the https server listens

func IdleTimeout

func IdleTimeout(t time.Duration) OptionFunc

IdleTimeout option sets a specific idle timeout. Set to 0 for no timeout (not recommended)

func ReadHeaderTimeout

func ReadHeaderTimeout(t time.Duration) OptionFunc

ReadHeaderTimeout option sets a specific read timeout. Set to 0 for no timeout (not recommended)

func ReadTimeout

func ReadTimeout(t time.Duration) OptionFunc

ReadTimeout option sets a specific read timeout. Set to 0 for no timeout (not recommended)

func ShutdownTimeout

func ShutdownTimeout(t time.Duration) OptionFunc

ShutdownTimeout option sets a specific shutdown timeout. Set to 0 for direct shutdown

func TLSAuto

func TLSAuto(email, dirCache string, hostnames ...string) OptionFunc

TLSAuto option configures TLS via a basic autocert manager

func TLSAutoManager

func TLSAutoManager(m *autocert.Manager) OptionFunc

TLSAutoManager option configures TLS via the provided autocert manager

func TLSFiles

func TLSFiles(certFile, keyFile string) OptionFunc

TLSFiles option configures TLS via the provided certificate and key files. When this option is provided the main handler will be served over https

func WriteTimeout

func WriteTimeout(t time.Duration) OptionFunc

WriteTimeout option sets a specific write timeout. Set to 0 for no timeout (not recommended)

type Server

type Server struct {
	// ShutdownTimeout specifies how long to wait until we cancel a graceful shutdown
	ShutdownTimeout time.Duration
	// HTTP serves a handler over http. If a TLS option is provided, this
	// handler will be a redirect handler that redirects to https.
	HTTP *http.Server

	// HTTPS serves the main handler over https. Can be nil when only serving over http
	HTTPS *http.Server
	// contains filtered or unexported fields
}

Server uses net/http servers to serve a handler

func New

func New(handler http.Handler, options ...OptionFunc) (*Server, error)

New creates a new server configured with the provided options.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe runs the server until it receives a kill signal or one of the http servers fails

Jump to

Keyboard shortcuts

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