site

package
v0.9.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ThemePrefix = "/-/theme/"
)

Variables

View Source
var MediaPrefixes = []string{
	"/local--files/",
	"/local--code/",
	"/local--html/",
	"/local--theme/",
}

Functions

func FromContext

func FromContext(ctx context.Context) *db.Site

FromContext returns nil when the request never passed through HostRules, which is every request in a test that builds its own.

func IsMediaPath

func IsMediaPath(path string) bool

func LookupHosts

func LookupHosts(rawHost, serverPort string) []string

func NewUnresolved

func NewUnresolved(bundle *i18n.Bundle, assets *static.Assets) http.Handler

A wildcard DNS record sends every subdomain to this server, so a mistyped one has to land somewhere that says so.

func PublicHost

func PublicHost(value string) bool

func Sandbox

func Sandbox(w http.ResponseWriter, current *db.Site, mimeType string)

A site whose files share its own domain would otherwise run an uploaded page with the visitor's session. The sandbox keeps the scripts but takes the origin away, and PDFs are spared because browsers refuse to show them sandboxed.

func StripPort

func StripPort(rawHost string) string

func ThemeURL

func ThemeURL(t *db.Theme) string

A site with no usable theme loads nothing, so the base stylesheet stays the only thing under the site's own CSS, which is what a wikidot theme expects.

func ThemeURLByID

func ThemeURLByID(ctx context.Context, d *db.DB, id *int64) (string, error)

func ValidHost

func ValidHost(value string) bool

A value no request can carry stores a site that nothing reaches and nothing reports, so a scheme or a path is refused here rather than later.

func WithSite

func WithSite(ctx context.Context, s *db.Site) context.Context

func Zone

func Zone(ctx context.Context) *time.Location

Types

type Action

type Action int
const (
	Serve Action = iota
	Redirect
)

type Decision

type Decision struct {
	Action   Action
	Location string
	// Headers go on the response after the handler runs. A redirect carries
	// none.
	Headers map[string]string
}

func Decide

func Decide(s Site, rawHost string, u *url.URL) Decision

type HostRules

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

HostRules is the redirect between the two domains plus the header pair that follows from which one the request arrived on. The asset bundle stays outside it, since it is answered before any of this runs.

func NewHostRules

func NewHostRules(sites Lookup, serverPort string, next, unresolved http.Handler) *HostRules

func (*HostRules) ServeHTTP

func (h *HostRules) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Lookup

type Lookup interface {
	SiteByHosts(ctx context.Context, hosts []string) (*db.Site, error)
}

Lookup resolves a request's Host to a site. *db.DB satisfies it.

type Site

type Site struct {
	Domain      string
	MediaDomain string
}

type ThemeFiles

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

func NewThemeFiles

func NewThemeFiles(root string) *ThemeFiles

NewThemeFiles serves out of the theme directory under root, which is files/.

func (*ThemeFiles) ServeHTTP

func (h *ThemeFiles) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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