mirror of
https://github.com/1f349/gomvn.git
synced 2024-12-21 15:34:05 +00:00
Lot errors from GetRepositories
This commit is contained in:
parent
03820c48de
commit
30379b0080
@ -55,7 +55,10 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal("[GoMVN] Error: invalid database: ", err)
|
||||
}
|
||||
mustHaveUser(db)
|
||||
err = mustHaveUser(db)
|
||||
if err != nil {
|
||||
log.Fatal("[GoMVN] Error: failed to ensure at least one user exists: ", err)
|
||||
}
|
||||
|
||||
repoBasePath := filepath.Join(wd, "repositories")
|
||||
err = os.MkdirAll(repoBasePath, os.ModePerm)
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetRepositories(basePath string, repository []string) map[string][]*database.Artifact {
|
||||
func GetRepositories(basePath string, repository []string) (map[string][]*database.Artifact, error) {
|
||||
result := map[string][]*database.Artifact{}
|
||||
for _, repo := range repository {
|
||||
result[repo] = []*database.Artifact{}
|
||||
repoPath := filepath.Join(basePath, repo)
|
||||
_ = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
|
||||
err := filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
|
||||
if strings.HasSuffix(path, ".pom") {
|
||||
path = strings.Replace(path, "\\", "/", -1)
|
||||
path = strings.Replace(path, repoPath+"/", "", 1)
|
||||
@ -22,8 +22,11 @@ func GetRepositories(basePath string, repository []string) map[string][]*databas
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func newArtifact(p string, mod time.Time) *database.Artifact {
|
||||
|
@ -14,7 +14,7 @@
|
||||
{{range $k, $v := .Repositories}}
|
||||
<ul>
|
||||
{{range $v}}
|
||||
<li><a href="{{ $k }}/{{ .GetPath }}" class="dir">{{ .Group }}:{{ .Artifact }}:{{ .Version }}</a>, last
|
||||
<li><a href="{{ $k }}/{{ .GetPath }}" class="dir">{{ .MvnGroup }}:{{ .Artifact }}:{{ .Version }}</a>, last
|
||||
modified {{ .Modified }}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/thanhpk/randstr"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@ -90,11 +91,19 @@ var indexHtml string
|
||||
|
||||
var indexTemplate = template.Must(template.New("index").Parse(indexHtml))
|
||||
|
||||
func (r *routeCtx) handleIndex(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||
_ = indexTemplate.Execute(rw, map[string]any{
|
||||
func (r *routeCtx) handleIndex(rw http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
|
||||
repositories, err := paths.GetRepositories(r.basePath, r.repository)
|
||||
if err != nil {
|
||||
http.Error(rw, "500 Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = indexTemplate.Execute(rw, map[string]any{
|
||||
"Name": r.name,
|
||||
"Repositories": paths.GetRepositories(r.basePath, r.repository),
|
||||
"Repositories": repositories,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("[GoMVN] Index template error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *routeCtx) handlePut(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||
|
Loading…
Reference in New Issue
Block a user