all repos — legit @ 889bf52d08fd7b38160a6435d6f0409acc6cba89

Unnamed repository; edit this file 'description' to name the repository.

internal/routes/util.go (view raw)

 1package routes
 2
 3import (
 4	"net/http"
 5	"os"
 6	"path/filepath"
 7	"strings"
 8
 9	"codeberg.org/maxwelljensen/legit/internal/git"
10)
11
12func isGoModule(gr *git.GitRepo) bool {
13	_, err := gr.FileContent("go.mod")
14	return err == nil
15}
16
17func getDisplayName(name string) string {
18	return strings.TrimSuffix(name, ".git")
19}
20
21func getDescription(path string) (desc string) {
22	db, err := os.ReadFile(filepath.Join(path, "description"))
23	if err == nil {
24		desc = string(db)
25	} else {
26		desc = ""
27	}
28	return
29}
30
31func (d *deps) isUnlisted(name string) bool {
32	for _, i := range d.c.Repo.Unlisted {
33		if name == i {
34			return true
35		}
36	}
37
38	return false
39}
40
41func (d *deps) isIgnored(name string) bool {
42	for _, i := range d.c.Repo.Ignore {
43		if name == i {
44			return true
45		}
46	}
47
48	return false
49}
50
51func setContentDisposition(w http.ResponseWriter, name string) {
52	h := "inline; filename=\"" + name + "\""
53	w.Header().Add("Content-Disposition", h)
54}
55
56func setGZipMIME(w http.ResponseWriter) {
57	setMIME(w, "application/gzip")
58}
59
60func setMIME(w http.ResponseWriter, mime string) {
61	w.Header().Add("Content-Type", mime)
62}