Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

752 B
Raw Blame
package layout

import (
	"net/http"

	"github.com/a-h/templ"
	"github.com/seaweedfs/seaweedfs/weed/admin/dash"
)

// ViewContext contains per-request metadata needed by layout templates.
type ViewContext struct {
	Request   *http.Request
	Username  string
	CSRFToken string
	URLPrefix string
}

// NewViewContext builds a ViewContext from request metadata.
func NewViewContext(r *http.Request, username, csrfToken string) ViewContext {
	return ViewContext{
		Request:   r,
		Username:  username,
		CSRFToken: csrfToken,
		URLPrefix: dash.URLPrefixFromContext(r.Context()),
	}
}

// P returns the URL prefix prepended to the given path as a templ.SafeURL.
func (v ViewContext) P(path string) templ.SafeURL {
	return templ.SafeURL(v.URLPrefix + path)
}