aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Nachum <me@yotam.net>2019-12-06 22:32:44 +0200
committerYotam Nachum <me@yotam.net>2019-12-06 22:32:44 +0200
commit177da57e0a193777672f9736c1e75e1f0d6fdad8 (patch)
tree10530e5d1c8a3e9a5c6950bf078a8b283e9cc161
parentHandle error from AddExtensionType (diff)
downloadshavit-177da57e0a193777672f9736c1e75e1f0d6fdad8.tar.gz
shavit-177da57e0a193777672f9736c1e75e1f0d6fdad8.zip
Add custom index file name
-rw-r--r--handler.go8
-rw-r--r--input.go13
2 files changed, 16 insertions, 5 deletions
diff --git a/handler.go b/handler.go
index addc538..804c4b2 100644
--- a/handler.go
+++ b/handler.go
@@ -59,9 +59,11 @@ func (h Handler) getFilePath(rawURL string) (string, error) {
return itemPath, nil
}
- indexPath := filepath.Join(itemPath, "index.gmi")
- if isFile(indexPath) {
- return indexPath, nil
+ for _, indexFile := range h.cfg.IndexFiles {
+ indexPath := filepath.Join(itemPath, indexFile)
+ if isFile(indexPath) {
+ return indexPath, nil
+ }
}
return "", gemini.Error{Err: fmt.Errorf("file not found"), Status: gemini.StatusNotFound}
diff --git a/input.go b/input.go
index f532476..57df49e 100644
--- a/input.go
+++ b/input.go
@@ -33,9 +33,14 @@ func getFlags() (Flags, error) {
// Config holds the main configuration data for the server
type Config struct {
+ // can be relative or absolute path
SourceDir string `toml:"source"`
- TLSCert string `toml:"tls_certificate"`
- TLSKey string `toml:"tls_key"`
+
+ // default to ["index.gmi"]
+ IndexFiles []string `toml:"index_files"`
+
+ TLSCert string `toml:"tls_certificate"`
+ TLSKey string `toml:"tls_key"`
}
func getConfig(path string) (Config, error) {
@@ -55,5 +60,9 @@ func getConfig(path string) (Config, error) {
return cfg, fmt.Errorf("failed to get absolute source dir: %v", err)
}
+ if len(cfg.IndexFiles) == 0 {
+ cfg.IndexFiles = []string{"index.gmi"}
+ }
+
return cfg, nil
}