netl

package module
v0.0.0-...-dbac86a Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 10 Imported by: 0

README

netl go.dev reference

netl helps to create net.listener. Possible configurations

  • vanilla
  • let's encrypt autocert
  • tls (opinated, secure configuration)
  • systemd socket-activation.

For usage see examples or listener_test.go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFieldIsMissing is used with FieldError when a required field is missing.
	ErrFieldIsMissing = errors.New("field is required")

	// ErrFieldWrongFormat is used with FieldError when a field has not the required format.
	ErrFieldWrongFormat = errors.New("field input has wrong format")
)

Functions

func FlagSet

func FlagSet(f *flag.FlagSet, cfg *Config)

FlagSet applies flags to given flag-set

func ValidateTLSFiles

func ValidateTLSFiles(cert, key string) (err error)

ValidateTLSFiles checks that cert and key are valid X509 certificates.

Types

type Addr

type Addr string

Addr represents a listener address

func AddrFromNetAddr

func AddrFromNetAddr(addr net.Addr) Addr

AddrFromNetAddr creates a new Addr from net.Addr

func AddrFromString

func AddrFromString(m string) (addr Addr, err error)

AddrFromString creates a new Addr from given string. Addr can be used in different variations. First, a simple ip-port combination (127.0.0.1:30221). To specify only the port, simply specify :$PORT. Then the daemon binds to all IP addresses and listen and $PORT. If you want to use the next free port you can specify port 0. If you pass the string "socket-activation" the socket activation of systemd is used. Additionally it is possible to define a socket name, which is separated by @ (socket-activation@nice-socket-name)

func (Addr) IsSocketActivation

func (addr Addr) IsSocketActivation() bool

IsSocketActivation checks if the Addr is a systemd-socket-activation

func (*Addr) Set

func (addr *Addr) Set(value string) (err error)

Set satisfies the flag.Value interface. Also used by https://github.com/kelseyhightower/envconfig..

func (Addr) String

func (addr Addr) String() string

type Config

type Config struct {
	// See comment for NewAddrFromString for possible configurations.
	Addr                Addr               `envconfig:"ADDR" ini:"addr" json:"addr" yaml:"addr"`
	TLSCert             string             `envconfig:"TLS_CERT" ini:"tls-cert" json:"tlsCert" yaml:"tlsCert"`
	TLSKey              string             `envconfig:"TLS_KEY" ini:"tls-key" json:"tlsKey" yaml:"tlsKey"`
	LetsEncryptEmail    string             `envconfig:"LETS_ENCRYPT_EMAIL" ini:"lets-encrypt-email" json:"letsEncryptEmail" yaml:"letsEncryptEmail"`
	LetsEncryptCacheDir string             `envconfig:"LETS_ENCRYPT_CACHE_DIR" ini:"lets-encrypt-cache-dir" json:"letsEncryptCacheDir" yaml:"letsEncryptCacheDir"`
	LetsEncryptDomains  LetsEncryptDomains `envconfig:"LETS_ENCRYPT_DOMAINS" ini:"lets-encrypt-domains" json:"letsEncryptDomains" yaml:"letsEncryptDomains"`
}

Config defines possible configuration for the http daemon

func Flag

func Flag() (cfg Config, err error)

Flag applies default flags and parse it

func (Config) Listen

func (cfg Config) Listen() (l net.Listener, err error)

Listen creates a new net.Listner based on the configuration

func (Config) SocketName

func (cfg Config) SocketName() (string, bool)

SocketName returns the socket name specified by the user. It is possible to define a socket name by appending it separated by an @ to SocketActivationPrefix in Config.Addr. If socket activation is not used, name will be empty a string and ok will be false.

func (Config) Validate

func (cfg Config) Validate() error

Validate verifies if Listener is valid.

type FieldError

type FieldError struct {
	Field string
	Err   error
	Value interface{}
}

FieldError is returned when Listener is not valid.

func (FieldError) Error

func (err FieldError) Error() string

Error satisfies error interface

type LetsEncryptDomains

type LetsEncryptDomains []string

LetsEncryptDomains defines a list of domains for which a certificate should be requested or managed by Let's encrypt.

func LetsEncryptDomainsFromString

func LetsEncryptDomainsFromString(value string) (domains LetsEncryptDomains, err error)

LetsEncryptDomainsFromString takes a list of comma seperated domains and creates a new LetsEncryptDomains list out of it.

func (*LetsEncryptDomains) Set

func (dd *LetsEncryptDomains) Set(value string) (err error)

Set satisfies the flag.Value interface. Also used by https://github.com/kelseyhightower/envconfig..

func (LetsEncryptDomains) String

func (dd LetsEncryptDomains) String() string

Jump to

Keyboard shortcuts

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