httpbase

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 8 Imported by: 3

README

Nacelle Base HTTP Process GoDoc CircleCI Coverage Status

Abstract HTTP server process for nacelle.


For a more full-featured HTTP server framework built on nacelle, see chevron.

Usage

The supplied server process is an abstract HTTP/HTTPS server whose behavior is determined by a supplied ServerInitializer interface. This interface has only an Init method that receives application config as well as the HTTP server instance, allowing handlers to be registered before the server accepts clients. There is an example included in this repository.

The following options can be supplied to the server constructor to tune its behavior.

  • WithTagModifiers registers the tag modifiers to be used when loading process configuration (see below). This can be used to change default hosts and ports, or prefix all target environment variables in the case where more than one HTTP server is registered per application (e.g. health server and application server, data plane and control plane server).
Configuration

The default process behavior can be configured by the following environment variables.

Environment Variable Default Description
HTTP_HOST 0.0.0.0 The host on which to accept connections.
HTTP_PORT 5000 The port on which to accept connections.
HTTP_CERT_FILE The path to the TLS cert file.
HTTP_KEY_FILE The path to the TLS key file.
HTTP_SHUTDOWN_TIMEOUT 5 The time (in seconds) the server can spend in a graceful shutdown.

The one of HTTP_CERT_FILE and HTTP_KEY_FILE are set, then they must both be set. Setting these will start a TLS server.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadCertConfig = fmt.Errorf("cert file and key file must both be supplied or both be omitted")

Functions

This section is empty.

Types

type Config

type Config struct {
	HTTPHost           string `env:"http_host" file:"http_host" default:"0.0.0.0"`
	HTTPPort           int    `env:"http_port" file:"http_port" default:"5000"`
	HTTPCertFile       string `env:"http_cert_file" file:"http_cert_file"`
	HTTPKeyFile        string `env:"http_key_file" file:"http_key_file"`
	RawShutdownTimeout int    `env:"http_shutdown_timeout" file:"http_shutdown_timeout" default:"5"`

	ShutdownTimeout time.Duration
}

func (*Config) PostLoad

func (c *Config) PostLoad() error

type ConfigFunc

type ConfigFunc func(*options)

ConfigFunc is a function used to configure an instance of a Worker.

func WithTagModifiers

func WithTagModifiers(modifiers ...nacelle.TagModifier) ConfigFunc

WithTagModifiers applies the given tag modifiers on config load.

type Server

type Server struct {
	Logger   nacelle.Logger           `service:"logger"`
	Services nacelle.ServiceContainer `service:"services"`
	Health   nacelle.Health           `service:"health"`
	// contains filtered or unexported fields
}

func NewServer

func NewServer(initializer ServerInitializer, configs ...ConfigFunc) *Server

func (*Server) Init

func (s *Server) Init(config nacelle.Config) (err error)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() (err error)

type ServerInitializer

type ServerInitializer interface {
	Init(nacelle.Config, *http.Server) error
}

type ServerInitializerFunc

type ServerInitializerFunc func(nacelle.Config, *http.Server) error

func (ServerInitializerFunc) Init

func (f ServerInitializerFunc) Init(config nacelle.Config, server *http.Server) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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