spielzeugweb

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOCAL_DEV_REGION   = "region_local_dev"
	LOCAL_DEV_ALLOC_ID = "dev1234"
)
View Source
const (
	DefaultIdleTimeout     = 30 * time.Second
	DefaultReadTimeout     = 5 * time.Second
	DefaultWriteTimeout    = 10 * time.Second
	DefaultShutdownTimeout = 30 * time.Second
)
View Source
const (
	HSTS_max_age_seconds = 60 * 60 * 24 * 90 // 90 days
)

Variables

This section is empty.

Functions

func BuildInfoAsHtmlFunc

func BuildInfoAsHtmlFunc(bi BuildInfoer) func() template.HTML

Forced into this API to make it easily invocable by template

func CanonicalizeHandler

func CanonicalizeHandler(
	logger *slog.Logger,
	domainCanonicalizer RedirectFunc,
	pathCanonicalizer RedirectFunc,
	next http.Handler,
) http.Handler

func DontRedirect

func DontRedirect(*http.Request) (url.URL, int)

func EnvOr

func EnvOr(key, defaultVal string) string

func FlyInfoAsHtmlFunc

func FlyInfoAsHtmlFunc(fi FlyInfoer) func() template.HTML

Forced into this API to make it easily invocable by template

func GenBase32Etag

func GenBase32Etag(b []byte) string

Base64 uses '/' and '+' chars and I'm not sure '+' is valid for ETAGs, so we use Base32 to cut risk

func GetGitInfo

func GetGitInfo() string

func GetNonceOrDefault

func GetNonceOrDefault(ctx context.Context, defaultVal string) string

func GetRequestIdOrDefault

func GetRequestIdOrDefault(ctx context.Context, defaultVal string) string

func HeaderOr

func HeaderOr(hdr http.Header, key, defaultVal string) []string

func RecoverPanicHandler

func RecoverPanicHandler(logger *slog.Logger, next http.Handler) http.Handler

func RewriteHandler

func RewriteHandler(
	logger *slog.Logger,
	rewrite map[string]string,
	next http.Handler,
) http.Handler

Transparent internal rewrites

func SecurityHeadersHandler

func SecurityHeadersHandler(logger *slog.Logger, next http.Handler) http.Handler

XXX As written, attacker may be able to potentially exhaust random pool!

func TagRequestWithUniqueIdHandler

func TagRequestWithUniqueIdHandler(logger *slog.Logger, next http.Handler) http.Handler

Types

type BuildInfoer

type BuildInfoer interface {
	GitRevision() string
}

type FlyInfoer

type FlyInfoer interface {
	FlyAllocID() string
	FlyRegion() string
}

type RedirTarget

type RedirTarget struct {
	ToPath string
	Code   int
}

type RedirectFunc

type RedirectFunc func(*http.Request) (url.URL, int)

Returns "to" URL and redirection code if redirection warranted Returns code==0 if no redirection indicated

func DomainCanonicalizer

func DomainCanonicalizer(
	logger *slog.Logger,
	canonFQDN string,
	secondaryFQDNs []string,
) RedirectFunc

Should probably only be invoked in local/dev mode and not production Returned func returns (nil, http.StatusBadGateway) on error

func PathCanonicalizer

func PathCanonicalizer(
	logger *slog.Logger,
	redirMap map[string]RedirTarget,
) RedirectFunc

Redirect old URLs picked up by search engines

type ServerWithShutdown

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

func NewServerWithShutdown

func NewServerWithShutdown() *ServerWithShutdown

func (*ServerWithShutdown) Run

func (s *ServerWithShutdown) Run(
	logger *slog.Logger,
	flyRegion string,
	httpPort int,
	h http.Handler,
	settings ...Setting,
) error

func (*ServerWithShutdown) Shutdown

func (s *ServerWithShutdown) Shutdown() error

This should panic if called twice

type Setting

type Setting struct {
	Kind SettingKind
	Val  int
}

type SettingKind

type SettingKind int
const (
	CfgIdleTimeout SettingKind = iota
	CfgReadTimeout
	CfgWriteTimeout
	CfgShutdownTimeout
)

type Static

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

func (*Static) GetDigestUrlByFilePath

func (s *Static) GetDigestUrlByFilePath(fpath string) (_ string, ok bool)

func (*Static) Init

func (static *Static) Init(
	logger *slog.Logger,
	filesys fs.FS,
	notFoundFunc http.HandlerFunc,
) error

func (*Static) ServeHTTP

func (s *Static) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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