httpserver

package
Version: v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultShutdownTimeout is the default ShutdownTimeout (see Config).
	DefaultShutdownTimeout = time.Second * 10
)

Variables

This section is empty.

Functions

func BaseTLSConfig

func BaseTLSConfig() *tls.Config

BaseTLSConfig returns a tls.Config with some good default settings for security.

Types

type Config

type Config struct {
	// Name is the name of the server. It is only used for logging. It can
	// be empty.
	Name string

	// Address is the address to bind the server to. It must be set.
	Address string

	// AddressTLS is the address to bind the https server to. It must be set, but is not used if TLS is not configured.
	AddressTLS string

	// Whether requests and responses are logged or not. Sometimes you might provide your own logging middleware instead.
	TrafficLogging bool

	// TLSConfig is the TLS configuration for the server. It is optional.
	TLSConfig *TLSConfig

	// ShutdownTimeout controls how long to wait for requests to finish before
	// returning from Run() after the context is canceled. It defaults to
	// 10 seconds if unset. If set to a negative value, the server will be
	// closed immediately.
	ShutdownTimeout time.Duration
}

Config holds the HTTP server configuration.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP server.

architecture: Endpoint

func New

func New(log *zap.Logger, handler http.Handler, txtRecords *sharing.TXTRecords, config Config) (*Server, error)

New creates a new URL Service Server.

func (*Server) Addr

func (server *Server) Addr() string

Addr returns the public address.

func (*Server) AddrTLS

func (server *Server) AddrTLS() string

AddrTLS returns the public TLS address.

func (*Server) Run

func (server *Server) Run(ctx context.Context) (err error)

Run runs the server.

func (*Server) Shutdown

func (server *Server) Shutdown() (err error)

Shutdown gracefully shuts the server down, with a given timeout. If timeout is less than 0, all connections are closed immediately instead of waiting.

type TLSConfig

type TLSConfig struct {
	// CertMagic obtains and renews TLS certificates and staples OCSP responses
	// Setting this to true will mean the server obtains certificate through Certmagic
	// and no other config such as CertDir, or CertFile will be considered.
	CertMagic bool

	// CertMagicKeyFile is a path to a file containing the CertMagic service account key.
	CertMagicKeyFile string

	// CertMagicEmail is the email address to use when creating an ACME account
	CertMagicEmail string

	// CertMagicStaging use staging CA endpoints
	CertMagicStaging bool

	// CertMagicBucket bucket to use for certstorage
	CertMagicBucket string

	// PublicURLs is a list of URLs to issue on a Let's Encrypt cert if enabled.
	PublicURLs []string

	// ConfigDir is a path for storing certificate cache data for Let's Encrypt.
	ConfigDir string

	// CertDir provides a path containing one or more certificates that should
	// be loaded. Certs and key files must have the same filename so they can be
	// paired, e.g. mycert.key, and mycert.crt. This config setting is mutually
	// exclusive from CertFile and KeyFile.
	CertDir string

	// CertFile is a path to a file containing a corresponding cert for KeyFile.
	CertFile string

	// KeyFile is a path to a file containing a corresponding key for CertFile.
	KeyFile string

	// Ctx context for the oauth2 package which gcslock and gcsops use.
	// oauth2 stores the context passed into its constructors.
	Ctx context.Context
}

TLSConfig is a struct to handle the preferred/configured TLS options.

Source Files

Jump to

Keyboard shortcuts

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