mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-08-31 23:06:53 +00:00
34 lines
923 B
Go
34 lines
923 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"atcr.io/pkg/appview/db"
|
|
"atcr.io/pkg/appview/middleware"
|
|
)
|
|
|
|
// PageData contains common fields shared across all page templates
|
|
type PageData struct {
|
|
User *db.User // Logged-in user (nil if not logged in)
|
|
Query string // Search query from URL parameter
|
|
RegistryURL string // Base registry URL
|
|
}
|
|
|
|
// NewPageData creates a PageData struct with common fields populated from the request
|
|
func NewPageData(r *http.Request, registryURL string) PageData {
|
|
return PageData{
|
|
User: middleware.GetUser(r),
|
|
Query: r.URL.Query().Get("q"),
|
|
RegistryURL: registryURL,
|
|
}
|
|
}
|
|
|
|
// TrimRegistryURL removes http:// or https:// prefix from a URL
|
|
// for use in Docker commands where only the host:port is needed
|
|
func TrimRegistryURL(url string) string {
|
|
url = strings.TrimPrefix(url, "https://")
|
|
url = strings.TrimPrefix(url, "http://")
|
|
return url
|
|
}
|