tagpic

posix tagging gallery
git clone git://kloet.net/tagpic
Download | Log | Files | Refs | LICENSE

commit 82ff8d9a5ac82cd42661d7ef0b8ffd4256f94713
parent d0666f6f822608c8339a9f94835b254c29ac8d7a
Author: Andrew Kloet <andrew@kloet.net>
Date:   Thu, 17 Sep 2026 16:24:45 -0400

tagpicd: typing

Diffstat:
Mtagpicd.go | 45++++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/tagpicd.go b/tagpicd.go @@ -34,6 +34,20 @@ var ( port string ) +type ImageData struct { + URL string + Date string + Tags []string +} + +type PageData struct { + Tag string + Tags []string + Imgs []ImageData + Prev int + Next int +} + var tmpl = template.Must(template.New("").Parse(`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> @@ -87,7 +101,11 @@ func main() { } func gallery(w http.ResponseWriter, r *http.Request) { - entries, _ := os.ReadDir(imgDir) + entries, err := os.ReadDir(imgDir) + if err != nil { + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } var tags []string for _, e := range entries { if e.IsDir() { @@ -130,11 +148,12 @@ func gallery(w http.ResponseWriter, r *http.Request) { start := min((page-1)*pageSize, len(names)) end := min(start+pageSize, len(names)) - var data []map[string]any + var imgs []ImageData for _, name := range names[start:end] { var imgTags []string for _, t := range tags { - if _, err := os.Stat(filepath.Join(imgDir, t, name)); err == nil { + _, err := os.Stat(filepath.Join(imgDir, t, name)) + if err == nil { imgTags = append(imgTags, t) } } @@ -142,10 +161,10 @@ func gallery(w http.ResponseWriter, r *http.Request) { sec, _ := strconv.ParseInt(strings.TrimSuffix(name, filepath.Ext(name)), 10, 64) date := time.Unix(sec, 0).Format("2006-01-02 15:04") - data = append(data, map[string]any{ - "URL": "/f/" + name, - "Date": date, - "Tags": imgTags, + imgs = append(imgs, ImageData{ + URL: "/f/" + name, + Date: date, + Tags: imgTags, }) } @@ -156,11 +175,11 @@ func gallery(w http.ResponseWriter, r *http.Request) { // xhtml is the reasonable choice w.Header().Set("Content-Type", "application/xhtml+xml; charset=utf-8") - tmpl.Execute(w, map[string]any{ - "Tag": tag, - "Tags": tags, - "Imgs": data, - "Prev": page - 1, - "Next": next, + tmpl.Execute(w, PageData{ + Tag: tag, + Tags: tags, + Imgs: imgs, + Prev: page - 1, + Next: next, }) }