2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019-2021 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/>.
33 //go:embed hr-root.tmpl
35 HRRootTmpl = template.Must(template.New("hr-root").Parse(HRRootTmplRaw))
37 //go:embed hr-pkg.tmpl
39 HRPkgTmpl = template.Must(template.New("hr-pkg").Parse(HRPkgTmplRaw))
42 func serveHRRoot(w http.ResponseWriter, r *http.Request) {
43 files, err := ioutil.ReadDir(Root)
45 log.Println("error", r.RemoteAddr, "hr-root", err)
46 http.Error(w, err.Error(), http.StatusInternalServerError)
49 packages := make([]string, 0, len(files))
50 for _, f := range files {
51 packages = append(packages, f.Name())
53 sort.Strings(packages)
55 err = HRRootTmpl.Execute(&buf, struct {
63 log.Println("error", r.RemoteAddr, "hr-root", err)
64 http.Error(w, err.Error(), http.StatusInternalServerError)
70 func serveHRPkg(w http.ResponseWriter, r *http.Request) {
71 cols := strings.Split(strings.TrimRight(r.URL.Path, "/"), "/")
72 pkgName := cols[len(cols)-1]
73 meta, releases, err := getMD(pkgName, "")
75 if os.IsNotExist(err) {
78 log.Println("error", r.RemoteAddr, "json", pkgName, err)
79 http.Error(w, err.Error(), http.StatusInternalServerError)
84 err = HRPkgTmpl.Execute(&buf, struct {
88 Releases []*PkgReleaseInfo
96 log.Println("error", r.RemoteAddr, "root", err)
97 http.Error(w, err.Error(), http.StatusInternalServerError)