webserver

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package webserver sets up a simple http server that listens on a port and stops on SIGINT or SIGTERM. It exposes methods for other packages to register per-path handlers, and functions that will be called when the web server starts up and shuts down.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandler

func AddHandler(path string, handler func(http.ResponseWriter, *http.Request))

AddHandler adds a handler to the webserver. If a handler already exists on the specified path, it will be replaced.

func AddInitFunc added in v0.2.0

func AddInitFunc(f func())

AddInitFunc adds a function to be called before starting the server. Packages can use this to, for example, parse flags and dynamically add/remove handlers just before the server starts.

func AddShutdownFunc added in v0.2.0

func AddShutdownFunc(f func())

AddShutdownFunc adds a function to be called while stopping the server. Packages can use this to clean up if needed.

func GetOption

func GetOption(optflag *string, envvarname string, defaultvalue string) string

GetOption gets an the value for an option. The value can be, in descending order of preference: - provided as a command-line option

- provided as an environment variable

- the default value

func ListenAndServe

func ListenAndServe()

ListenAndServe starts the web server. It will stop on receiving SIGINT or SIGTERM.

func RemoveHandler

func RemoveHandler(path string)

RemoveHandler removes the handler on the specified path. If a handler does not exist on the specified path, nothing happens.

func SetRootHandler

func SetRootHandler(path string)

SetRootHandler sets a root handler, which will respond to / The handler has to be added using AddHandler before calling SetRootHandler. A nonexistant path will be ignored.

func Version added in v0.2.0

func Version() string

Version returns the version of the web server.

Types

This section is empty.

Jump to

Keyboard shortcuts

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