aboutsummaryrefslogtreecommitdiff
path: root/handle_group_index.go
blob: bc7a7f45d04ff701d81975e4a90d99ec85b83f38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"net/http"
	"os"
	"path/filepath"
	"strings"
)

func handle_group_repos(w http.ResponseWriter, r *http.Request, params map[string]string) {
	data := make(map[string]any)
	group_name := params["group_name"]
	data["group_name"] = group_name
	entries, err := os.ReadDir(filepath.Join(config.Git.Root, group_name))
	if err != nil {
		_, _ = w.Write([]byte("Error listing repos: " + err.Error()))
		return
	}

	repos := []string{}
	for _, entry := range entries {
		this_name := entry.Name()
		if strings.HasSuffix(this_name, ".git") {
			repos = append(repos, strings.TrimSuffix(this_name, ".git"))
		}
	}
	data["repos"] = repos

	err = templates.ExecuteTemplate(w, "group_repos", data)
	if err != nil {
		_, _ = w.Write([]byte("Error rendering template: " + err.Error()))
		return
	}
}