X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=list.go;h=3c056415555c9aace1ccac3c1edff55b6344e1e7;hb=ff8005cd81eda18fc9b0c6950c4a25000a7dff7e;hp=9c4c2912cb65e0d133df894441fa7145087e8b09;hpb=371b9da450b741c6dc50cf5427fcbdec4335d0fc;p=gocheese.git diff --git a/list.go b/list.go index 9c4c291..3c05641 100644 --- a/list.go +++ b/list.go @@ -1,6 +1,6 @@ /* GoCheese -- Python private package repository and caching proxy -Copyright (C) 2019-2021 Sergey Matveev +Copyright (C) 2019-2023 Sergey Matveev 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(` - - - - Simple index - - {{$Refresh := .RefreshURLPath}}{{range .Packages}} - {{.}}
-{{- end}} - - -`)) - HTMLReleasesTmpl = template.Must(template.New("list").Parse(` - - - - Links for {{.PkgName}} - - {{$Refresh := .RefreshURLPath}}{{$PkgName := .PkgName}}{{range .Releases}} - {{.Filename}}
-{{- end}} - - -`)) - 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 }