web

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrSiteExists = "site already exists"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Site

type Site struct {
	// Domain to respond to.
	Domain string `json:"domain"`
	// Certificate PEM file to load. Absolute path.
	Certificate string `json:"certificate,omitempty"`
	// Key PEM file to load. Absolute path.
	Key string `json:"key,omitempty"`
	// Owner is a user in the database.
	Owner string `json:"owner"`

	//
	// Internals
	//
	log.LogShortcuts
}

Site is the configuration for a specific domain.

func (*Site) DefaultHandler

func (s *Site) DefaultHandler(w http.ResponseWriter, r *http.Request)

DefaultHandler for testing.

func (*Site) SetLogger

func (s *Site) SetLogger(l *log.Logger)

SetLogger changes the logger object and sets the message shortcuts for convenience.

type Timeouts added in v0.6.0

type Timeouts struct {
	// Idle timeout defaults to 30 seconds.
	Idle time.Duration `json:"idle"`
	// Read timeout defaults to 10 seconds.
	Read time.Duration `json:"read"`
	// Write timeout defaults to 10 seconds.
	Write time.Duration `json:"write"`
	// Shutdown timeout defaults to 3 seconds.
	Shutdown time.Duration `json:"shutdown"`
}

Timeouts for web server.

type Web

type Web struct {
	sync.RWMutex
	sync.WaitGroup
	log.LogShortcuts
	http.Server

	// Address to bind the web server to.
	Address string `json:"address"`
	// Port is optional, and will default to 80 or 443, depending on presence of certificates.
	Port string `json:"port"`
	// SitePath is the directory where site configurations are stored.
	SitePath string `json:"sites"`
	// Secure servers prepare a default TLS configuration.
	Secure bool `json:"secure"`
	// Timeouts for connections and shutdown.
	Timeouts Timeouts `json:"timeouts"`
	// contains filtered or unexported fields
}

Web server configuration and runtime data.

func New

func New(address, port string, logger *log.Logger, secure bool) *Web

New creates a web server, configured with reasonable timeouts and a default handlers. Use AddSite() or LoadSites() to add handlers for domains.

func NewFromFile added in v0.5.0

func NewFromFile(name string, logger *log.Logger) (*Web, error)

NewFromFile creates a web server based on a JSON configuration file.

func (*Web) AddCertificate

func (w *Web) AddCertificate(cert tls.Certificate)

AddCertificate from loaded certificate.

func (*Web) AddSite

func (w *Web) AddSite(s *Site) error

AddSite to a web server. This is done on the fly without need of any restarting.

func (*Web) Init added in v0.5.0

func (w *Web) Init(l *log.Logger)

Init sets up basics for a web server.

func (*Web) LoadSites added in v0.5.0

func (w *Web) LoadSites() error

LoadSites from JSON files in the site config directory (non-recursively).

func (*Web) RebuildCertificates

func (w *Web) RebuildCertificates() error

RebuildCertificates reloads the certificates from all sites.

func (*Web) SetLogger

func (w *Web) SetLogger(l *log.Logger)

SetLogger changes the logger object and sets the message shortcuts for convenience.

func (*Web) Start

func (w *Web) Start()

Start the webserver.

func (*Web) Stop

func (w *Web) Stop() error

Stop the webserver and try to wait until all connections are done. Give up after half a configured timeout.

Jump to

Keyboard shortcuts

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