web

package module
v1.0.0-...-3087924 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 16 Imported by: 0

README

web

GoDoc Go Report Card Coverage Status Build Status CircleCI

Description

This is a micro framework for create web servers, based on net/http with manage and route functions.

Framework do not interfere with the style of your code and do not require to somehow modify Handlers and HandlerFunc functions. But at the same time framework adds to your application a full-functions routing, middlewares and lots of useful functionality or just simplifies your code.

Dependencies
none
Install
go get gopkg.in/webnice/web.v1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrAlreadyRunning

func ErrAlreadyRunning() error

ErrAlreadyRunning Error: Web server already running

func ErrListenSystemdFDS

func ErrListenSystemdFDS() error

ErrListenSystemdFDS Error: Environment variable LISTEN_FDS is empty or contains an invalid value

func ErrListenSystemdNotFound

func ErrListenSystemdNotFound() error

ErrListenSystemdNotFound Error: Systemd socket with name not found

func ErrListenSystemdPID

func ErrListenSystemdPID() error

ErrListenSystemdPID Error: Environment variable LISTEN_PID is empty or contains an invalid value

func ErrListenSystemdUnexpectedNumber

func ErrListenSystemdUnexpectedNumber() error

ErrListenSystemdUnexpectedNumber Error: Unexpected number of socket activation fds

func ErrNoConfiguration

func ErrNoConfiguration() error

ErrNoConfiguration Error: Web server configuration is missing or nil

func ErrTLSIsNil

func ErrTLSIsNil() error

ErrTLSIsNil Error: TLS configuration is empty

Types

type Configuration

type Configuration struct {
	// HostPort (readonly) Адрес составленный автоматически из Host:Port
	// Значение создаётся автоматически при инициализации конфигурации
	// Default value: ":http"
	HostPort string `yaml:"-" json:"-"`

	// Address Публичный адрес на котором сервер доступен извне
	// Например если сервер находится за прокси, тут указывается реальный адрес подключения к серверу
	// Default value: "" - make automatically
	Address string `yaml:"Address" json:"address"`

	// TLSPublicKeyPEM Путь и имя файла содержащего публичный ключ (сертификат) в PEM формате, включая CA сертификаты
	// всех промежуточных центров сертификации, если ими подписан ключ
	TLSPublicKeyPEM string `yaml:"TLSPublicKeyPEM" json:"tls_public_key_pem"`

	// TLSPrivateKeyPEM Путь и имя файла содержащего приватный ключ в PEM формате
	TLSPrivateKeyPEM string `yaml:"TLSPrivateKeyPEM" json:"tls_private_key_pem"`

	// Host IP адрес или имя хоста на котором запускается web сервер,
	// можно указывать 0.0.0.0 для всех ip адресов
	// Default value: ""
	Host string `yaml:"Host" json:"host"`

	// Port tcp/ip порт занимаемый сервером
	// Default value: 80
	Port uint16 `yaml:"Port" json:"port"`

	// Socket Unix socket на котором поднимается сервер, только для unix-like операционных систем Linux, Unix, Mac
	// Default value: "" - unix socket is off
	Socket string `yaml:"Socket" json:"socket"`

	// Mode Режим работы, tcp, tcp4, tcp6, unix, unixpacket, socket, systemd
	// systemd - systemd is configures to open the port or unix socket and passes over the file descriptor the port
	// listener to the service. See systemd.socket(5) manual.
	// Default value: "tcp"
	Mode string `yaml:"Mode" json:"mode"`

	// ReadTimeout Время в наносекундах ожидания запроса включая ReadHeaderTimeout
	// Если не указано или рано 0 - таймаута нет
	// Default value: 0 - no timeout
	ReadTimeout time.Duration `yaml:"ReadTimeout" json:"read_timeout"`

	// ReadHeaderTimeout Время в наносекундах ожидания заголовка запроса
	// Если не указано или рано 0 - таймаута нет
	// Default value: 0 - no timeout
	ReadHeaderTimeout time.Duration `yaml:"ReadHeaderTimeout" json:"read_header_timeout"`

	// WriteTimeout Время в наносекундах ожидания выдачи ответа
	// Если не указано или рано 0 - таймаута нет
	// Default value: 0 - no timeout
	WriteTimeout time.Duration `yaml:"WriteTimeout" json:"write_timeout"`

	// IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled
	// Если не указано или рано 0 - таймаута нет
	// Default value: 0 - no timeout
	IdleTimeout time.Duration `yaml:"IdleTimeout" json:"idle_timeout"`

	// ShutdownTimeout is the maximum amount of time to wait for the server graceful shutdown
	// Если не указано или рано 0 - таймаута нет
	// Default value: 30s
	ShutdownTimeout time.Duration `yaml:"ShutdownTimeout" json:"shutdown_timeout"`

	// MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line
	// Default value: 1 MB (from net/http/DefaultMaxHeaderBytes)
	MaxHeaderBytes int `yaml:"MaxHeaderBytes" json:"max_header_bytes"`

	// KeepAliveDisable if is equal true, keep alive are disabled, if false - keep alive are enabled
	// Default value: false - keep alive are enabled
	KeepAliveDisable bool `yaml:"KeepAliveDisable" json:"keep_alive_disable"`

	// ProxyProtocol if is equal true, accepting the PROXY Protocol
	// The PROXY protocol enables web server to receive client connection information passed through proxy servers and
	// load balancers such as HAproxy and Amazon Elastic Load Balancer (ELB).
	// With the PROXY protocol, web server can learn the originating IP address from HTTP, SSL, HTTP/2, SPDY, WebSocket, and TCP.
	ProxyProtocol bool `yaml:"ProxyProtocol" json:"proxy_protocol"`
}

Configuration is a structure of web server configuration

type Error

type Error struct{}

Error object of package

func Errors

func Errors() *Error

Errors All errors of a known state that can return functions of the package

type Interface

type Interface interface {
	// ListenAndServe listens on the TCP network address addr and then calls Serve on incoming connections
	ListenAndServe(addr string) Interface

	// ListenAndServeTLS listens on the TCP network address address with TLS and then calls Serve with handler
	// to handle requests on incoming connections
	ListenAndServeTLS(addr string, certFile string, keyFile string, tlsConfig *tls.Config) Interface

	// ListenAndServeWithConfig Fully configurable web server listens and then calls Serve on incoming connections
	ListenAndServeWithConfig(*Configuration) Interface

	// ListenAndServeTLSWithConfig Fully configurable web server listens and then calls Serve on incoming connections
	ListenAndServeTLSWithConfig(conf *Configuration, tlsConfig *tls.Config) Interface

	// ListenersSystemdWithoutNames returns a net.Listener for each matching socket type passed to this process from systemd
	ListenersSystemdWithoutNames() (ret []net.Listener, err error)

	// ListenersSystemdWithNames maps a listener name to a set of net.Listener instances passed to this process from systemd
	ListenersSystemdWithNames() (ret map[string][]net.Listener, err error)

	// ListenersSystemdTLSWithoutNames returns a net.listener for each matching TCP socket type passed to this process from systemd
	ListenersSystemdTLSWithoutNames(tlsConfig *tls.Config) (ret []net.Listener, err error)

	// ListenersSystemdTLSWithNames maps a listener name to a net.Listener with the associated TLS configuration passed to this process from systemd
	ListenersSystemdTLSWithNames(tlsConfig *tls.Config) (ret map[string][]net.Listener, err error)

	// NewListener Make new listener from web server configuration
	NewListener(conf *Configuration) (ret net.Listener, err error)

	// NewListenerTLS Make new listener with TLS from web server configuration
	NewListenerTLS(conf *Configuration, tlsConfig *tls.Config) (ret net.Listener, err error)

	// Serve accepts incoming connections on the Listener, creating a new service goroutine for each
	Serve(net.Listener) Interface

	// ServeTLS accepts incoming connections on the listener with TLS configuration, creating a new web server goroutine
	ServeTLS(ltn net.Listener, tlsConfig *tls.Config) Interface

	// Error Return last error of web server
	Error() error

	// Wait while web server is running
	Wait() Interface

	// Stop web server
	Stop() Interface

	// Route interface
	Route() route.Interface

	// Errors interface
	Errors() errors.Interface

	// Handlers interface
	Handlers() handlers.Interface
}

Interface is an interface

func New

func New() Interface

New is a constructor of new web server implementation

Directories

Path Synopsis
middleware
Package proxyproto implements Proxy Protocol (v1 and v2) parser and writer, as per specification: http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
Package proxyproto implements Proxy Protocol (v1 and v2) parser and writer, as per specification: http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt

Jump to

Keyboard shortcuts

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