web

package
v0.0.0-...-1a2dda4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileServer

func FileServer(root string) http.Handler

FileServer is a FileServerHandler with the NotFound handler set to http.NotFound.

func FileServerHandler

func FileServerHandler(root string, notFound http.HandlerFunc) http.Handler

FileServerHandler creates a file server that serves files from from a "Root" folder. It will call "NotFound" HandlerFunc if the file cannot be found on the system. In the event where the path is a directory, it will not redirect and instead call "NotFound" HandlerFunc.

Types

type Server

type Server struct {
	Addr    string        // TCP address to listen on, ":http" if empty
	Handler http.Handler  // handler to invoke, http.DefaultServeMux if nil
	Timeout time.Duration // Timeout to wait for shutdown
}

Server will create a http.Server from the Go standard library

Example

ExampleServer is an example of how to launch a server If you use docker, [docker stop](https://docs.docker.com/compose/reference/stop/) has a default timeout of 10 seconds, the graceful timeout should be set to expire before then.

s := Server{
	Addr:    ":8080",
	Timeout: 5 * time.Second,
}
log.Println("Starting...")
log.Println(s.ListenAndServe())
Output:

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe mirrors the function from the Go standard library ListenAndServe always returns a non-nil error

Jump to

Keyboard shortcuts

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