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