Help us shape the future of Go! Take the 2026 Go Developer Survey

httpserver

package module
v0.0.0-...-2c0ddcd Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: Unlicense Imports: 10 Imported by: 0

README

HTTP Server

Go library providing a simple HTTP server controllable, and stoppable by SIGINT.

Install

go get github.com/normegil/httpserver

Documentation

See godoc for documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// Address controls the address used by the HTTP server
	Address string
	// Port controls the address used by the HTTP server
	Port int
	// Handler will be passed to the HTTP server to handle HTTP calls
	Handler http.Handler
	// Closer will be used to handler errors in ressource closing in defer statement. By default, the error is discarded
	Closer closer.CloseErrorHandler
}

Server is an object used to launch an HTTP server

func (Server) Listen

func (s Server) Listen() *ServerControl

Listen launch the HTTP server in a separate goroutine and return an instance to control the server lifecycle.

type ServerControl

type ServerControl struct {
	// HTTP Server controlled by this instance
	Server *http.Server
	// Channel setup to listen for SIGINT
	Interrupted chan os.Signal
	// Error channel used by the running server if any error is detected during launch or while running
	Errors chan error
	// contains filtered or unexported fields
}

ServerControl is used to access informations and control a running http server

func (ServerControl) Shutdown

func (c ServerControl) Shutdown(timeout time.Duration) error

Shutdown will shutdown the controlled server

func (*ServerControl) Status

func (c *ServerControl) Status() Status

Status function load current server status

func (*ServerControl) Wait

func (c *ServerControl) Wait() error

Wait will wait for the first server error, or a SIGINT signal. If a SIGINT is received, the control server will be shutdown

type Status

type Status int

Status represent the current HTTP server status

const (
	NotStarted Status = iota
	Starting
	Listening
	Closing
	Closed
	Error
)

Jump to

Keyboard shortcuts

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