http

package
v0.0.0-...-19169da Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 9 Imported by: 1

README

Nacelle Base HTTP Process

This package contains a base process implementation for an HTTP server. For a more full-featured HTTP framework, see chevron.

Usage

To use the server, initialize a process by passing a Server Initializer to the NewServer constructor. A server initializer is an object with an Init method that takes a nacelle config object (as all process initializer methods do) as well as an *http.Server. This hook is provided so the the application can independently configure the server's HTTP handler.

The server initializer will have services injected and will receive the nacelle config object on initialization as if it were a process.

To get a better understanding of the full usage, see the example.

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 the server accepts clients.
HTTP_PORT 5000 The port on which the server accepts clients.
HTTP_CERT_FILE An absolute path to a cert file.
HTTP_KEY_FILE An absolute path to a key file.
HTTP_SHUTDOWN_TIMEOUT 5 The duration (in seconds) to allow for a graceful shutdown.

If both a cert file and key file paths are provided, the server will serve TLS. It is an error to provide a path to a cert file or a path to a key file but not both.

Using Multiple Servers

In order to run multiple HTTP servers, tag modifiers can be applied during config registration. For more details on how to do this, see the example.

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" mask:"true" 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 ...config.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:"container"`
	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

Jump to

Keyboard shortcuts

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