Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ func runServe() {
logger := setupLogger(cfg.Log.Level, cfg.Log.Format)

// Create and start server
srv, err := server.New(cfg, logger)
srv, err := server.New(cfg, logger, server.BuildInfo{
Version: Version,
Commit: Commit,
})
if err != nil {
logger.Error("failed to create server", "error", err)
os.Exit(1)
Expand Down
15 changes: 11 additions & 4 deletions internal/server/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ package server

import "net/http"

// Layout carries per-request fields consumed by the shared base template
// (canonical URL, og:url). It is embedded in every page data struct so that
// templates can reference {{.UIBaseURL}} and {{.CanonicalPath}} alongside the
// page's own fields.
// BuildInfo identifies the running proxy binary.
type BuildInfo struct {
Version string
Commit string
}

// Layout carries shared fields consumed by the base template. It is embedded
// in every page data struct so templates can access canonical URL and build
// information alongside the page's own fields.
type Layout struct {
BuildInfo
UIBaseURL string
CanonicalPath string
}

func (s *Server) layoutFor(r *http.Request) Layout {
return Layout{
BuildInfo: s.buildInfo,
UIBaseURL: s.cfg.UIBaseURL,
CanonicalPath: r.URL.Path,
}
Expand Down
4 changes: 3 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ type Server struct {
db *database.DB
storage storage.Storage
logger *slog.Logger
buildInfo BuildInfo
http *http.Server
templates *Templates
cancel context.CancelFunc
healthCache *healthCache
}

// New creates a new Server with the given configuration.
func New(cfg *config.Config, logger *slog.Logger) (*Server, error) {
func New(cfg *config.Config, logger *slog.Logger, buildInfo BuildInfo) (*Server, error) {
// Initialize database
var db *database.DB
var err error
Expand Down Expand Up @@ -152,6 +153,7 @@ func New(cfg *config.Config, logger *slog.Logger) (*Server, error) {
db: db,
storage: store,
logger: logger,
buildInfo: buildInfo,
templates: &Templates{},
healthCache: hc,
}, nil
Expand Down
21 changes: 16 additions & 5 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ func newTestServer(t *testing.T) *testServer {

// Create a minimal server struct for the handlers
s := &Server{
cfg: cfg,
db: db,
storage: store,
logger: logger,
cfg: cfg,
db: db,
storage: store,
logger: logger,
buildInfo: BuildInfo{
Version: "test-version",
Commit: "test-commit",
},
templates: &Templates{},
healthCache: hc,
}
Expand Down Expand Up @@ -313,6 +317,9 @@ func TestDashboard(t *testing.T) {
if !strings.Contains(body, "Cached Artifacts") {
t.Error("dashboard should contain stats")
}
if !strings.Contains(body, "proxy test-version (test-commit)") {
t.Error("dashboard footer should contain build information")
}
if !strings.Contains(body, "Popular Packages") {
t.Error("dashboard should contain popular packages section")
}
Expand Down Expand Up @@ -1327,10 +1334,14 @@ func TestNewServer_StorageConnectivityCheck(t *testing.T) {

logger := slog.New(slog.NewTextHandler(io.Discard, nil))

srv, err := New(cfg, logger)
buildInfo := BuildInfo{Version: "test-version", Commit: "test-commit"}
srv, err := New(cfg, logger, buildInfo)
if err != nil {
t.Fatalf("New() failed: %v", err)
}
if srv.buildInfo != buildInfo {
t.Errorf("build info = %#v, want %#v", srv.buildInfo, buildInfo)
}

// On Windows, OpenBucket normalises to file:///C:/path; on Unix the
// absolute path already starts with /, so file:// + /path == file:///path.
Expand Down
5 changes: 5 additions & 0 deletions internal/server/templates/layout/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ <h3 class="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3">About</h
<i data-lucide="github" class="w-4 h-4"></i><span>github.com/git-pkgs/proxy</span>
</a>
</p>
{{if .Version}}
<p class="text-xs text-gray-500 dark:text-gray-500 mt-2">
proxy {{.Version}}{{if .Commit}} ({{.Commit}}){{end}}
</p>
{{end}}
Comment on lines +15 to +19
</div>
<div>
<h3 class="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-3">Resources</h3>
Expand Down