Documentation ¶
Overview ¶
Package server provides a webserver constructor.
To use this, you must also use the registry package to register handlers. That is generally done in modules by doing the following:
func init() { registry.Register("/hello", handler) }
handler can be an existing http.Handler or can be made by using an
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request{})
You can start the server in a few ways:
// Start the server on the :http port (80). s, err := New() if err != nil { // Do something } s.ListenAndServe() // This blocks. // Start on any free port. l, err := net.Listen("tcp", ":0") // Start listening on any free port. if err != nil { // Do something } fmt.Println("Server listening on: %s", l.Addr().String()) s, err := New() if err != nil { // Do something } s.Serve(l) // This blocks. // Start on a specific port. s, err := New(Addr(":2560")) if err != nil { // Do something } s.ListenAndServe() // This blocks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
Option is an optional argument to the New() constructor.
func ErrorLog ¶
ErrorLog allows you to specify the errror log for the server. If not set, will use os.Stderr.
func LogRequests ¶
func LogRequests() Option
LogRequests will log all of the incoming requests. This is useful for debugging only.
Directories ¶
Path | Synopsis |
---|---|
Package registry contains a registry of URL patterns to http.Handlers and a Register() method for registering a handler during init() in a module.
|
Package registry contains a registry of URL patterns to http.Handlers and a Register() method for registering a handler during init() in a module. |
Click to show internal directories.
Click to hide internal directories.