server

package
v0.0.0-...-f21bc9d Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package server provides simple utilities to create new http.Server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...ServerOption) (*http.Server, error)

New can receive zero or multiple ServerOption and returns a new http.Server with these options applied. It returns an error if there is no server.Handler specified or if the server.Addr is an empty string after having applied the received options.

Types

type ServerOption

type ServerOption func(s *http.Server)

ServerOption defines an option to a new http.Server.

func WithBasicAuth

func WithBasicAuth(user string, password string, h http.Handler) ServerOption

WithBasicAuth receives an user, a password and a http.Handler and returns a ServerOption that applies it to the http.Server.

func WithGracefulShutdown

func WithGracefulShutdown(done <-chan struct{}, quit chan<- struct{}) ServerOption

WithGracefulShutdown receives a done and a quit chan and returns a ServerOption that initializes a goroutine that listens to the done chan to try to shutdown the http.Server gracefully.

func WithHandler

func WithHandler(handler http.Handler) ServerOption

WithHandler receives an http.Handler and returns a ServerOption that applies it to the http.Server.

func WithIdleTimeout

func WithIdleTimeout(timeout time.Duration) ServerOption

WithIdleTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.

func WithListenAddr

func WithListenAddr(addr string) ServerOption

WithListenAddr receives an address and returns a ServerOption that applies it to the http.Server.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) ServerOption

WithReadTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) ServerOption

WithWriteTimeout receives a timeout and returns a ServerOption that applies it to the http.Server.

Jump to

Keyboard shortcuts

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