golang.org/x/build@v0.0.0-20240506185731-218518f32b70/perf/app/index.go (about) 1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package app 6 7 import ( 8 _ "embed" 9 "log" 10 "net/http" 11 12 "github.com/google/safehtml/template" 13 "golang.org/x/build/perfdata" 14 ) 15 16 // index redirects / to /search. 17 func (a *App) index(w http.ResponseWriter, r *http.Request) { 18 ctx := r.Context() 19 20 t, err := template.New("index.html").ParseFS(tmplFS, "template/index.html") 21 if err != nil { 22 http.Error(w, err.Error(), 500) 23 return 24 } 25 26 var uploads []perfdata.UploadInfo 27 ul := a.StorageClient.ListUploads(ctx, "", []string{"by", "upload-time"}, 16) 28 defer ul.Close() 29 for ul.Next() { 30 uploads = append(uploads, ul.Info()) 31 } 32 if err := ul.Err(); err != nil { 33 log.Printf("failed to fetch recent uploads: %v", err) 34 } 35 36 w.Header().Set("Content-Type", "text/html; charset=utf-8") 37 if err := t.Execute(w, struct{ RecentUploads []perfdata.UploadInfo }{uploads}); err != nil { 38 http.Error(w, err.Error(), 500) 39 return 40 } 41 }