httputil

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: CC0-1.0 Imports: 17 Imported by: 2

Documentation

Overview

Package httputil contains a HTTP/HTTPS Server which can be stopped via signals or a Shutdown() call.

Index

Constants

View Source
const SigShutdown = 1

SigShutdown is used to signal a request for shutdown

Variables

View Source
var ErrSigShutdown = errors.New("Server was shut down")

ErrSigShutdown indicates that a signal was received

Functions

func CheckLocalRedirect

func CheckLocalRedirect(urlString string) error

CheckLocalRedirect checks if a given redirect URL is a local redirect. The function returns an error in all other cases.

func RandomFileServer

func RandomFileServer(paths []string, errHandler func(err error)) http.Handler

RandomFileServer returns a handler that serves all HTTP requests with the contents of a random file. The file is picked from a predefined list.

func SingleFileServer

func SingleFileServer(path string, errHandler func(err error)) http.Handler

SingleFileServer returns a handler that serves all HTTP requests with the contents of a single file.

Types

type HTTPServer

type HTTPServer struct {
	LastError error // Last recorded error
	Running   bool  // Flag if the server is running
	// contains filtered or unexported fields
}

HTTPServer data structure

func (*HTTPServer) RunHTTPSServer

func (hs *HTTPServer) RunHTTPSServer(keypath string, certFile string, keyFile string,
	laddr string, wgStatus *sync.WaitGroup) error

RunHTTPSServer starts a HTTPS Server which can be stopped via ^C (Control-C). It is assumed that all routes have been added prior to this call.

keypath should be set to a path containing the TLS certificate and key. certFile should be the file containing the TLS certificate. keyFile should be the file containing the private key for the TLS connection. laddr should be the local address which should be given to net.Listen. wgStatus is an optional wait group which will be notified once the server is listening and once the server has shutdown.

This function will not return unless the server is shutdown.

func (*HTTPServer) RunHTTPServer

func (hs *HTTPServer) RunHTTPServer(laddr string, wgStatus *sync.WaitGroup) error

RunHTTPServer starts a HTTP Server which can be stopped via ^C (Control-C). It is assumed that all routes have been added prior to this call.

laddr should be the local address which should be given to net.Listen. wgStatus is an optional wait group which will be notified once the server is listening and once the server has shutdown.

This function will not return unless the server is shutdown.

func (*HTTPServer) Shutdown

func (hs *HTTPServer) Shutdown()

Shutdown sends a shutdown signal.

Directories

Path Synopsis
Package access contains access control code for webservers.
Package access contains access control code for webservers.
Package auth contains user authentication code for webservers.
Package auth contains user authentication code for webservers.
Package user contains user session management for webservers.
Package user contains user session management for webservers.

Jump to

Keyboard shortcuts

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