Abstract HTTP server
The github.com/go-nacelle/httpbase
package provides an abstract HTTP server process.
This library supplies an abstract HTTP server process whose behavior can be configured by implementing a ServerInitializer
interface. For a more full-featured HTTP server framework built on nacelle, see chevron.
An HTTP process is created by supplying an initializer, described below, that controls its behavior.
|
|
A server initializer is a struct with an Init
method that takes a context and an http.Server as parameters. This method may return an error value, which signals a fatal error to the process that runs it. This method provides an extension point to register handlers to the server instance before the process accepts connections.
The following example registers an HTTP handler function to the server that will handle all incoming requests. Each request atomically increments a request counter on the containing initializer struct and returns its new value. In more complex applications, an HTTP router, such as gorilla/mux should likely be used.
|
|
A simple server initializer stuct that does not need additional methods, state, or dependency instances injected via a service container can use the server initializer function wrapper instead.
|
|
You can see an additional example of an HTTP process in the example repository, specifically the server initializer.