~sotirisp/kindleto

e4ee1b6addc5b8035191a9055309bec48756b6e7 — Sotiris Papatheodorou 1 year, 10 months ago 5e8828e
Move names of index files in util package

It will allow reusing them in multiple places.
2 files changed, 13 insertions(+), 4 deletions(-)

M file/proxy.go
A util/index.go
M file/proxy.go => file/proxy.go +3 -4
@@ 132,11 132,10 @@ func Proxy(w http.ResponseWriter, r *http.Request, u *url.URL) error {
		// Attempt to open index.gmi or index.gemini but allow
		// explicitly listing the directory by ending the path in "/.".
		if !strings.HasSuffix(u.Path, "/.") {
			for _, ext := range []string{"gmi", "gemini"} {
				index := "/index." + ext
				s, err := os.Stat(filename + index)
			for _, index := range util.IndexNames() {
				s, err := os.Stat(filename + "/" + index)
				if err == nil && !s.IsDir() {
					uu, err := url.Parse(u.String() + index)
					uu, err := url.Parse(u.String() + "/" + index)
					if err == nil {
						return Proxy(w, r, uu)
					}

A util/index.go => util/index.go +10 -0
@@ 0,0 1,10 @@
// SPDX-FileCopyrightText: 2022 Sotiris Papatheodorou
// SPDX-License-Identifier: GPL-3.0-or-later

package util

// IndexNames returns the basenames of files that are served automatically
// in place of the directory that contains them.
func IndexNames() []string {
	return []string{"index.gmi", "index.gemini"}
}