]> Cypherpunks.ru repositories - gocheese.git/blobdiff - list.go
Use an updated recfile library
[gocheese.git] / list.go
diff --git a/list.go b/list.go
index 9c4c2912cb65e0d133df894441fa7145087e8b09..8567877d336b49a3c51ffceb63ef942399d086da 100644 (file)
--- a/list.go
+++ b/list.go
@@ -1,6 +1,6 @@
 /*
 GoCheese -- Python private package repository and caching proxy
-Copyright (C) 2019-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2019-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -19,12 +19,12 @@ package main
 
 import (
        "bytes"
+       _ "embed"
        "encoding/hex"
        "errors"
        "fmt"
        "html/template"
        "io/fs"
-       "io/ioutil"
        "log"
        "net/http"
        "os"
@@ -37,38 +37,19 @@ import (
 
 // https://warehouse.pypa.io/api-reference/legacy.html
 var (
-       HTMLRootTmpl = template.Must(template.New("root").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <meta name="pypi:repository-version" content="1.0">
-    <title>Simple index</title>
-  </head>
-  <body>{{$Refresh := .RefreshURLPath}}{{range .Packages}}
-    <a href="{{$Refresh}}{{.}}/">{{.}}</a><br/>
-{{- end}}
-  </body>
-</html>
-`))
-       HTMLReleasesTmpl = template.Must(template.New("list").Parse(`<!DOCTYPE html>
-<html>
-  <head>
-    <meta name="pypi:repository-version" content="1.0">
-    <title>Links for {{.PkgName}}</title>
-  </head>
-  <body>{{$Refresh := .RefreshURLPath}}{{$PkgName := .PkgName}}{{range .Releases}}
-    <a href="{{$Refresh}}{{$PkgName}}/{{.Filename -}}
-        #{{range $a, $d := .Digests}}{{$a}}={{$d}}{{end -}}
-        {{with .HasSig}} data-gpg-sig=true{{end}}">{{.Filename}}</a><br/>
-{{- end}}
-  </body>
-</html>
-`))
-       KnownExts = []string{".tar.bz2", ".tar.gz", ".whl", ".zip", ".egg",
+       //go:embed root.tmpl
+       HTMLRootTmplRaw string
+       HTMLRootTmpl    = template.Must(template.New("root").Parse(HTMLRootTmplRaw))
+
+       //go:embed list.tmpl
+       HTMLReleasesTmplRaw string
+       HTMLReleasesTmpl    = template.Must(template.New("list").Parse(HTMLReleasesTmplRaw))
+       KnownExts           = []string{".tar.bz2", ".tar.gz", ".whl", ".zip", ".egg",
                ".exe", ".dmg", ".msi", ".rpm", ".deb", ".tgz"}
 )
 
 func listRoot(w http.ResponseWriter, r *http.Request) {
-       files, err := ioutil.ReadDir(Root)
+       files, err := os.ReadDir(Root)
        if err != nil {
                log.Println("error", r.RemoteAddr, "root", err)
                http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -165,7 +146,7 @@ func listDir(pkgName string, doSize bool) (int64, []*PkgReleaseInfo, error) {
                                continue
                        }
                        delete(files, fn)
-                       digest, err := ioutil.ReadFile(filepath.Join(dirPath, fn))
+                       digest, err := os.ReadFile(filepath.Join(dirPath, fn))
                        if err != nil {
                                return 0, nil, err
                        }