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 ¶
- func AddHandler(path string, handler func(http.ResponseWriter, *http.Request))
- func AddInitFunc(f func())
- func AddShutdownFunc(f func())
- func GetOption(optflag *string, envvarname string, defaultvalue string) string
- func ListenAndServe()
- func RemoveHandler(path string)
- func SetRootHandler(path string)
- func Version() string
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 ¶
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.
Types ¶
This section is empty.