server

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 11 Imported by: 0

README

Server

This starts a http or an http/https server using Let's Encrypt certificates which auto renew via acme controller.

Uses graceful shutdown when it's time to die, meaning in-flight connections finish and are not dropped in the middle of the request while new requests are rejected during the shutdown process.

This package supports github.com/zxdev/env package and tags.


// Server structure; supports the zxdev/env package
type Server struct {
	Host     string `env:"require" default:"localhost" help:"localhost or FQDN"`
	Mirror   bool   `default:"false" help:"http request policy [mirror, 400]"`
	CertPath string `default:"/var/certs"`
	opt      *http.Server
}

The default senario is http on localhost:1455, however when a FQDN (eg. example.com) is configured as a HOST paramater, then requests will be served based on the server.Mirror policy.

server.Mirror = true responsed on port 80 or 443. server.Mirror = false returns 400 response codes for http requests requiring port 443 connections


	// bootstrap
	var param params
	var srv server.Server
	environ := env.NewEnv(&srv)

	// paths
	param.authPath = env.Dir(environ.Var, "conf", "auth.keys")

	// handlers
	router := server.Public(server.Heartbeat, nil, nil)
	authkey.NewAuth(&param.authPath, router).Silent()

	// start graceful managers
	grace := env.NewGraceful()
	grace.Manager(srv.Configure(&http.Server{
		Handler:           router,
		ReadHeaderTimeout: time.Second * 5,
		ReadTimeout:       time.Second * 10,
		WriteTimeout:      time.Second * 30,
	}))

	grace.Done()
	grace.Wait()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Heartbeat

func Heartbeat() string

Heartbeat; default response

func Public

func Public(heartbeat func() string, dlPath, docPath *string) *chi.Mux

Public represents a common set of routes for use with the chi mux router [root, heartbeat, endpoints, download, documentation] and returns the chi Router interface

Types

type Server

type Server struct {
	Host     string `env:"H,require" default:"localhost" help:"localhost or FQDN"`
	Mirror   bool   `default:"off" help:"http request policy [mirror|400]"`
	CertPath string `default:"/var/certs"`
	// contains filtered or unexported fields
}

Server structure; supports the zxdev/env package

func (*Server) Configure

func (srv *Server) Configure(opt *http.Server) *Server

Configure is a *Server configurator that takes *http.Server object and applies defaults to opt when these reasonable defaults are not set; expects the Handler to have been already set

func (*Server) Start

func (srv *Server) Start(ctx context.Context)

Start an http and/or https server using Let's Encrypt with a http redirect policy as defined by *Server.Redirect

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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