http

package
v1.56.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package http provides a registration interface for http services

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpt = Options{
	ListenAddr:         "127.0.0.1:8080",
	ServerReadTimeout:  1 * time.Hour,
	ServerWriteTimeout: 1 * time.Hour,
	MaxHeaderBytes:     4096,
}

DefaultOpt is the default values used for Options

View Source
var Help = `` /* 1549-byte string literal not displayed */

Help contains text describing the http server to add to the command help.

Functions

func AddFlags

func AddFlags(flagSet *pflag.FlagSet)

AddFlags adds flags for the httplib

func AddFlagsPrefix

func AddFlagsPrefix(flagSet *pflag.FlagSet, prefix string, Opt *Options)

AddFlagsPrefix adds flags for the httplib

func Mount

func Mount(pattern string, h http.Handler) error

Mount attaches another http.Handler along ./pattern/*

func Restart

func Restart() error

Restart or start the default http server using the default options and no handlers

func Route

func Route(pattern string, fn func(r chi.Router)) (chi.Router, error)

Route mounts a sub-Router along a `pattern` string.

func Router

func Router() (chi.Router, error)

Router returns the server base router

func SetOptions

func SetOptions(opt Options)

SetOptions thread safe setter for the default server options

func Shutdown

func Shutdown() error

Shutdown gracefully shuts down the default http server

func URL

func URL() string

URL of default http server

func Wait

func Wait()

Wait blocks while the default http server is serving requests

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware function signature required by chi.Router.Use()

type Options

type Options struct {
	ListenAddr         string        // Port to listen on
	BaseURL            string        // prefix to strip from URLs
	ServerReadTimeout  time.Duration // Timeout for server reading data
	ServerWriteTimeout time.Duration // Timeout for server writing data
	MaxHeaderBytes     int           // Maximum size of request header
	SslCert            string        // SSL PEM key (concatenation of certificate and CA certificate)
	SslKey             string        // SSL PEM Private key
	ClientCA           string        // Client certificate authority to verify clients with
}

Options contains options for the http Server

func GetOptions

func GetOptions() Options

GetOptions thread safe getter for the default server options

type Server

type Server interface {
	Router() chi.Router
	Route(pattern string, fn func(r chi.Router)) chi.Router
	Mount(pattern string, h http.Handler)
	Shutdown() error
}

Server interface of http server

func NewServer

func NewServer(listeners, tlsListeners []net.Listener, opt Options) (Server, error)

NewServer instantiates a new http server using provided listeners and options This function is provided if the default http server does not meet a services requirements and should not generally be used A http server can listen using multiple listeners. For example, a listener for port 80, and a listener for port 443. tlsListeners are ignored if opt.SslKey is not provided

Directories

Path Synopsis
Package serve deals with serving objects over HTTP
Package serve deals with serving objects over HTTP

Jump to

Keyboard shortcuts

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