server

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 33 Imported by: 1

Documentation

Overview

Package server provides HTTP server implementation. The server provided in here is opinionated and comes with good defaults.

Index

Constants

View Source
const (
	MethodAll     = "ALL"
	MethodGet     = http.MethodGet
	MethodHead    = http.MethodHead
	MethodPost    = http.MethodPost
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch
	MethodDelete  = http.MethodDelete
	MethodConnect = http.MethodConnect
	MethodOptions = http.MethodOptions
	MethodTrace   = http.MethodTrace
)

Variables

This section is empty.

Functions

func CertOpts

func CertOpts(certFile, keyFile, domain string) opts

CertOpts returns a new opts that has sensible defaults given certFile & keyFile.

func CreateDevCertKey

func CreateDevCertKey() (certFile, keyFile string)

CreateDevCertKey generates and saves(to disk) a certifiate and key that can be used to configure a tls server. This is only meant to be used for development/local settings. The certificate is self-signed & a best effort is made to add its CA to the OS trust store.

func DevOpts

func DevOpts() opts

DevOpts returns a new opts that has sensible defaults for tls, especially for dev environments.

func LetsEncryptOpts

func LetsEncryptOpts(email, domain string) opts

LetsEncryptOpts returns a new opts that procures certificates from Letsencrypt.

func NewMux

func NewMux(l log.Logger, opt middleware.Opts, rts Routes) *mux

NewMux creates a new mux.

func NewOpts

func NewOpts(
	port uint16,
	readHeaderTimeout time.Duration,
	readTimeout time.Duration,
	writeTimeout time.Duration,
	handlerTimeout time.Duration,
	idleTimeout time.Duration,
	certFile string,
	keyFile string,
	email string,
	domain string,
) opts

NewOpts returns a new opts. If certFile is a non-empty string, this will enable tls from certificates found on disk. If email is a non-empty string, this will enable tls from certificates procured from letsencrypt. domain can be an exact domain, subdomain or wildcard.

func NewRoute

func NewRoute(
	pattern string,
	method string,
	handler http.HandlerFunc,
) route

NewRoute creates a new route.

func Run

func Run(h http.Handler, o opts, l log.Logger) error

Run listens on a network address and then calls Serve to handle requests on incoming connections. It sets up a server with the parameters provided by o.

The server shuts down cleanly after receiving any terminating signal. If the opts supplied include a certificate and key, the server will accept https traffic and also automatically handle http->https redirect.

Types

type Routes

type Routes []route

Routes is a list of all the route for an application.

Directories

Path Synopsis
Package automax automatically sets GOMEMLIMIT & GOMAXPROCS to match the linux container memory quota, if any.
Package automax automatically sets GOMEMLIMIT & GOMAXPROCS to match the linux container memory quota, if any.

Jump to

Keyboard shortcuts

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