2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2022 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 //go:embed hr-root.tmpl
34 HRRootTmpl = template.Must(template.New("hr-root").Parse(HRRootTmplRaw))
36 //go:embed hr-pkg.tmpl
38 HRPkgTmpl = template.Must(template.New("hr-pkg").Parse(HRPkgTmplRaw))
41 func serveHRRoot(w http.ResponseWriter, r *http.Request) {
42 files, err := os.ReadDir(Root)
44 log.Println("error", r.RemoteAddr, "hr-root", err)
45 http.Error(w, err.Error(), http.StatusInternalServerError)
48 packages := make([]string, 0, len(files))
49 for _, f := range files {
50 packages = append(packages, f.Name())
52 sort.Strings(packages)
54 err = HRRootTmpl.Execute(&buf, struct {
62 log.Println("error", r.RemoteAddr, "hr-root", err)
63 http.Error(w, err.Error(), http.StatusInternalServerError)
69 func serveHRPkg(w http.ResponseWriter, r *http.Request) {
70 cols := strings.Split(strings.TrimRight(r.URL.Path, "/"), "/")
71 pkgName := cols[len(cols)-1]
72 meta, releases, err := getMD(pkgName, "")
74 if os.IsNotExist(err) {
77 log.Println("error", r.RemoteAddr, "json", pkgName, err)
78 http.Error(w, err.Error(), http.StatusInternalServerError)
83 err = HRPkgTmpl.Execute(&buf, struct {
87 Releases []*PkgReleaseInfo
95 log.Println("error", r.RemoteAddr, "root", err)
96 http.Error(w, err.Error(), http.StatusInternalServerError)